XML DOM - Node Object
Node object
The Node object represents a single node in the document tree.
The nodes here can be: element nodes, attribute nodes, text nodes, and all the Node typesother node types mentioned in this chapter.
Note that although all objects inherit the Node properties/methods for handling parent and child nodes, not all objects can contain parent or child nodes. For example, a Text node may not contain child nodes, so adding a child node to a text node may cause a DOM error.
Node Object Properties
| property | Description |
|---|---|
| baseURI | Returns the absolute base URI of the node. |
| childNodes | Returns a node list of the node's child nodes. |
| firstChild | Returns the first child node of the node. |
| lastChild | Returns the last child node of the node. |
| localName | Returns the local part of the node's name. |
| namespaceURI | Returns the namespace URI of the node. |
| nextSibling | Returns the node immediately following the element. |
| nodeName | Returns the name of the node, according to its type. |
| nodeType | Returns the type of the node. |
| nodeValue | Sets or returns the value of the node, according to its type. |
| ownerDocument | Returns the root element of the node (the document object). |
| parentNode | Returns the parent node of the node. |
| prefix | Sets or returns the namespace prefix of the node. |
| previousSibling | Returns the node immediately preceding the element. |
| textContent | Sets or returns the text content of the node and its descendants. |
Node Object Methods
| Method | Description |
|---|---|
| appendChild() | Adds a new child node to the end of the node's list of child nodes. |
| cloneNode() | Clones the node. |
| compareDocumentPosition() | Compares the document positions of two nodes. |
| getFeature(feature,version) | Returns a DOM object that can perform specialized APIs with the specified feature and version. |
| getUserData(key) | Returns the object associated with a key on the node. This object must first have been set on the node by calling setUserData with the same key. |
| hasAttributes() | Returns ture if the node has attributes, otherwise returns false. |
| hasChildNodes() | Returns true if the node has child nodes, otherwise returns false. |
| insertBefore() | Inserts a new child node before an existing child node. |
| isDefaultNamespace(URI) | Returns whether the specified namespaceURI is default. |
| isEqualNode() | Checks whether two nodes are equal. |
| isSameNode() | Checks whether two nodes are the same node. |
| isSupported(feature,version) | Returns whether the specified feature is supported on this node. |
| lookupNamespaceURI() | Returns the namespace URI matching the specified prefix. |
| lookupPrefix() | Returns the prefix matching the specified namespace URI. |
| normalize() | Puts all text nodes under the node (including attributes) into a "normal" format in which only structure (such as elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, that is, there are neither adjacent Text nodes nor empty Text nodes. |
| removeChild() | Remove a child node. |
| replaceChild() | Replace a child node. |
| setUserData(key,data,handler) | Associates an object with a key on the node. |