Element class

An Element object represents an XML element node. An element may have other Element, Comment and Text nodes as children. Furthermore an element may have attributes (these are not considered to be children).

Element inherits from the Node class, so all functions defined for Node can be used with Element.

Name

getQualifiedName( ) : String

Returns the qualified element name, i.e. including the namespace prefix if there is one.

getBaseName( ) : String

Returns the element name without the namespace prefix.

getPrefix( ) : String

Returns the namespace prefix or the empty string if there is none.

getNamespaceURI( ) : String

Returns the namespace URI corresponding to namespace prefix or the default namespace URI for the document if there is no prefix or the empty string if there is no prefix and no default namespace.

Child nodes

hasChildNodes( ) : Boolean

Returns true if this element has any child nodes, and false if not.

getChildNodes( ) : NodeList

Returns the list of child nodes of this element, in document order or an empty list if the element has no child nodes.

getFirstChild( ) : Node

Returns the first child node of this element or null if there is none.

getLastChild( ) : Node

Returns the last child node of this element or null if there is none.

appendChild( new-child : Node )

Appends a new child node to the list of children for this element.

insertBefore( new-child : Node, ref-child : Node )

Inserts a new child node before the specified reference node, which must be in the list of children of this element.

removeChild( oldChild : Node ) : Node

Removes the specified node from the list of children of this element, and returns the removed node.

replaceChild( newChild : Node, oldChild : Node ) : Node

Replaces the specified child of this element with another node, and returns the removed node.

Attributes

getAttributes( ) : AttrList

Returns the list of attributes of this element, in arbitrary order. If there are no attributes, returns an empty list.

addAttribute( attribute : Attr )

Adds the specified attribute to the element or replaces an existing attribute with the same name.

getAttributeValue( qualified-name : String, prefix-map : Map ) : String

Returns the value for the element's attribute with the specified qualified name or null if there is no such attribute. If the qualified name includes a prefix it is resolved using the map in the second argument, otherwise the second argument may be null.

addAttribute( qualified-name : String, prefix-map : Map, value : String )

Adds an attribute to the element with the specified qualified name and value or replaces an existing attribute with the same name. If the qualified name includes a prefix it is resolved using the map in the second argument, otherwise the second argument may be null.