class Element
Extends Parent
Includes Namespace
Represents a tagged XML element. Elements are characterized by having children, attributes, and names, and can themselves be children.
Attributes
Methods
Attributes
attributes (reader)
Mechanisms for accessing attributes and child elements of this element.
context (accessor)
elements (reader)
Mechanisms for accessing attributes and child elements of this element.
Methods
add_attribute
Returns
the Attribute added
Adds an attribute to this element, overwriting any existing attribute by the same name.
add_attributes
Add multiple attributes to this element. EG: el.add_attributes( {"name1"=>"value1", "name2"=>"value2"} ) el.add_attributes( [ ["name1","value1"], ["name2"=>"value2"] ] )
add_element
Returns
the Element that was added
Adds a child to this element, optionally setting attributes in the element.
add_text
Returns
self. NOTE that contrary to most REXML methods, the object added to the parent is not returned.
A helper method to add a Text child. Actual Text instances can be added with regular Parent methods, such as add() and <<()
delete_attribute
Returns
the attribute removed, or nil if this Element did not contain a matching attribute
Removes an attribute
delete_element
Returns
the element that was removed.
Deletes a child element.
each_element_with_text
Iterates through the children, yielding for each Element that has a particular text set. @see text
Element
Returns
an array with [tag_name_S, closed_B, attributes_A]
A helper method, to consolidate the common code between parse and parse_stream. @return an array with [tag_name_S, closed_B, attributes_A]
get_elements
Returns
an array of Elements that match the supplied path
This is a little slower than calling elements.each directly.
get_text
Returns
the first Text child encountered.
This is the same method as text(), only this method returns the actual Text object, rather than the String content.
has_attributes
Returns
true if this element has any attributes set, false otherwise.
has_elements
Returns
true if this element has at least one child Element
has_text
Returns
true if this element has at least one Text child
namespace
Returns
the URI for a namespace, or the empty string if no such namespace is declared
next_element
Returns the next sibling that is an element, or nil if there is no Element sibling after this one
prefixes
Returns
an Array of all defined namespaces
previous_element
Returns the previous sibling that is an element, or nil if there is no Element sibling prior to this one
root
Returns
the root of the document that this element belongs to. If this element doesn't belong to a document, but does belong to another Element, the parent's root will be returned, until the earliest ancestor is found.
text
Returns
the String content of the first child text element encountered.
A convenience method which returns the first child text element. NOTE that an element may have multiple Text elements, perhaps separated by other children; consider: "<p>some text <b>this is bold!</b> more text<p>" The element <p> has two text elements, "some text " and " more text". This method would return only the first, "some text ".
text=
Returns
self. NOTE that contrary to most REXML methods, the replaced content is not returned.
Sets the first Text child of this object. See text() for a discussion about Text children. If a Text child already exists, the child is replaced by this content. This means that Text content can be deleted by calling this method with a nil argument. In this case, the next Text child becomes the first Text child. In no case is the order of any siblings disturbed.
write
Writes out this element, and recursively, all children.