REXML::Element

Constants

Attributes

Mechanisms for accessing attributes and child elements of this element.

context[RW]

The context holds information about the processing environment, such as
whitespace handling.

elements[R]

Mechanisms for accessing attributes and child elements of this element.

Public Class Methods

new( arg = UNDEFINED, parent=nil, context=nil )click to toggle source

Constructor

arg

if not supplied, will be set to the default value. If a String, the name of
this object will be set to the argument. If an Element, the object will be shallowly cloned; name,
attributes, and namespaces will be copied. Children will not
be copied.

parent

if supplied, must be a Parent, and will be used
as the parent of this object.

context

If supplied, must be a hash containing context items. Context items
include:

:respect_whitespace the value of this is :all or
an array of strings being the names of the elements to respect whitespace
for. Defaults to :all.

:compress_whitespace the value can be :all or an
array of strings being the names of the elements to ignore whitespace on.
Overrides :respect_whitespace.

:ignore_whitespace_nodes the value can be :all or
an array of strings being the names of the elements in which to ignore
whitespace-only nodes. If this is set, Text nodes
which contain only whitespace will not be added to the document tree.

:raw can be :all, or an array of strings being
the names of the elements to process in raw mode. In raw mode, special
characters in text is not converted to or from entities.

Public Instance Methods

add_attribute( key, value=nil )click to toggle source

Adds an attribute to this element, overwriting any existing attribute by
the same name.

key

can be either an Attribute or a String. If an
Attribute, the attribute is added to the list
of Element attributes. If String, the argument
is used as the name of the new attribute, and the value parameter must be
supplied.

value

Required if key is a String, and ignored if the first argument
is an Attribute. This is a String, and is
used as the value of the new Attribute. This
should be the unnormalized value of the attribute (without entities).

# File rexml/element.rb, line 296defadd_elementelement, attrs=nilraise"First argument must be either an element name, or an Element object"ifelement.nil?el = @elements.add(element)
attrs.eachdo|key, value|el.attributes[key]=valueendifattrs.kind_of?Hashelend

Must be an Element, String, or
Integer. If Element, the element
is removed. If String, the element is found (via XPath) and removed. <em>This means that any
parent can remove any descendant.<em> If Integer, the Element indexed by that number will be removed.

Evaluates to the root node 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.

Note that this is not the same as the document element. In the following
example, <a> is the document element, and the root node is the parent
node of the document element. You may ask yourself why the root node is
useful: consider the doctype and XML declaration, and any processing
instructions before the document element… they are children of the root
node, or siblings of the document element. The only time this isn’t true is
when an Element is created that is not part of
any Document. In this case, the ancestor that
has no parent acts as the root node.

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.

text

If a String, a new Text child is created and added
to this Element as the first Text child. If Text, the text
is set as the first Child element. If nil, then
any existing first Text child is removed.