XML DOM - NodeObject
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 allNode Typeother node types mentioned in this chapter.
Please note that although all objects inherit the Node properties/methods used to handle parent and child nodes, not all objects can contain parent or child nodes. For example, Text nodes 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 child nodes of the node. |
| 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, depending on its type. |
| nodeType | Returns the type of the node. |
| nodeValue | Sets or returns the value of a node, depending on its type. |
| ownerDocument | Returns the root element of a node (the document object). |
| parentNode | Returns the parent node of the node. |
| prefix | Sets or returns the namespace prefix of a node. |
| previousSibling | Returns the node immediately preceding the element. |
| textContent | Sets or returns the text content of a node and its descendants. |
Node Object Methods
| Methods | Description |
|---|---|
| appendChild() | Adds a new child node to the end of the node's child node list. |
| cloneNode() | Clone node. |
| compareDocumentPosition() | Compares the document position of two nodes. |
| getFeature(feature,version) | Returns a DOM object that can execute a specialized API with the specified feature and version. |
| getUserData(key) | Returns the object associated with a key on a node. This object must first be set to this node by calling setUserData with the same key. |
| hasAttributes() | Returns true if the node has attributes, otherwise false. |
| hasChildNodes() | Returns true if the node has child nodes, otherwise false. |
| insertBefore() | Inserts a new child node before an existing child node. |
| isDefaultNamespace(URI) | Returns whether the specified namespaceURI is the 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 that matches the specified prefix. |
| lookupPrefix() | Returns the prefix that matches the specified namespace URI. |
| normalize() | Puts all text nodes under a node (including attributes) into a "standard" format, in which only structure (such as elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes. For example, there are neither adjacent Text nodes nor empty Text nodes. |
| removeChild() | Delete child node. |
| replaceChild() | Replace child node. |
| setUserData(key,data,handler) | Associates an object with a key on the node. |
other extensions