XML DOM Element Object
- Previous Page DOM Document
- Next Page DOM Attr
Element object
The Element object represents an element in an XML document. Elements can contain attributes, other elements, or text. If an element contains text, it is represented by the text node.
Important note:Text is always stored in text nodes. A common mistake in DOM processing is to navigate to an element node and assume that this node contains text. However, even the simplest element node has a text node below it. For example, in <year>2005</year>, there is an element node (year), and below this node there is a text node containing the text (2005).
Since the Element object is also a node, it can inherit the properties and methods of the Node object.
Attributes of the Element object.
Attribute | Description |
---|---|
attributes | Returns the NamedNodeMap of the element's attribute. |
baseURI | Returns the absolute base URI of the element. |
childNodes | Returns the NodeList of the element's child nodes. |
firstChild | Returns the first child of the element. |
lastChild | Returns the last child of the element. |
localName | Returns the local part of the element name. |
namespaceURI | Returns the namespace URI of the element. |
nextSibling | Returns the node immediately following the element. |
nodeName | Returns the name of the node, depending on its type. |
nodeType | Returns the type of the node. |
ownerDocument | Returns the root element (document object) of the element. |
parentNode | Returns the parent node of the element. |
prefix | Sets or returns the namespace prefix of the element. |
previousSibling | Returns the node immediately preceding the element. |
schemaTypeInfo | Returns the type information associated with the element. |
tagName | Returns the name of the element. |
textContent | Sets or returns the text content of the element and its descendants. |
Methods of Element object
Method | Description |
---|---|
appendChild() | Appends a new child node to the end of the node's child node list. |
cloneNode() | Clones a node. |
compareDocumentPosition() | Compares the document position of two nodes. |
getAttribute() | Returns the value of the attribute. |
getAttributeNS() | Returns the value of the attribute (with namespace). |
getAttributeNode() | Returns an attribute node as an Attribute object. |
getAttributeNodeNS() | Returns an attribute node (with namespace) as an Attribute object. |
getElementsByTagName() | Returns a NodeList of matching element nodes and their child nodes. |
getElementsByTagNameNS() | Returns a NodeList of matching element nodes (with namespace) and their child nodes. |
getFeature(feature,version) | Returns a DOM object that implements the specialized API for the specified feature and version. |
getUserData(key) | Returns the object associated with the key on the node. The object must be set to this node first, by using the same key to call setUserData. |
hasAttribute() | Returns whether the element has an attribute with the specified name. |
hasAttributeNS() | Return whether the element has an attribute that matches the specified name and namespace. |
hasAttributes() | Return whether the element has attributes. |
hasChildNodes() | Return whether the element has child nodes. |
insertBefore() | Insert a new child node before the existing child nodes. |
isDefaultNamespace(URI) | Return whether the specified namespaceURI is the default. |
isEqualNode() | Check if two nodes are equal. |
lookupNamespaceURI() | Return the namespace URI that matches the specified prefix. |
lookupPrefix() | Return the prefix that matches the specified namespace URI. |
normalize() |
The normalize() method removes empty text nodes and connects adjacent text nodes. Normalize all text nodes under the element (including attributes), where only structural elements (such as elements, comments, processing instructions, CDATA sections, and entity references) separate text nodes. That is, there are no adjacent text nodes, nor are there empty text nodes. |
removeAttribute() | Remove the specified attribute. |
removeAttributeNS() | Remove the specified attribute (with a namespace). |
removeAttributeNode() | Remove the specified attribute node. |
removeChild() | Remove the child node. |
replaceChild() | Replace the child node. |
setUserData(key,data,handler) | Associate the object with the key on the element. |
setAttribute() | Add a new attribute. |
setAttributeNS() | Add a new attribute (with a namespace). |
setAttributeNode() | Add a new attribute node. |
setAttributeNodeNS(attrnode) | Add a new attribute node (with a namespace). |
setIdAttribute(name,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute as a user-defined ID attribute. |
setIdAttributeNS(uri,name,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute (with a namespace) as a user-defined ID attribute. |
setIdAttributeNode(idAttr,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute as a user-defined ID attribute. |
- Previous Page DOM Document
- Next Page DOM Attr