DOM Node
XML DOM - Node Object
Node Object
The Node object represents an individual node in the document tree.
The nodes here can be: element nodes, attribute nodes, text nodes, and all other node types mentioned in the Node Types chapter.
Please note that although all objects inherit the Node properties/methods used to handle parent nodes and child nodes, not all objects can contain parent nodes or child nodes. For example, a Text node may not contain child nodes, so adding child nodes to a text node may cause a DOM error.
Node object properties
Properties | Description |
---|---|
baseURI | Return the absolute base URI of the node. |
childNodes | Returns the 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 name. |
namespaceURI | Returns the namespace URI of the node. |
nextSibling | Returns the node immediately after the element. |
nodeName | Returns the name of the node, according to its type. |
nodeType | Returns the type of node. |
nodeValue | Sets or returns the value of a node, according to its type. |
ownerDocument | Returns the root element of the node (document object). |
parentNode | Returns the parent node of the node. |
prefix | Set or return the namespace prefix of the node. |
previousSibling | Returns the node immediately before the element. |
textContent | Set or return the text content of the node and its descendants. |
Node Object Method
Method | Description |
---|---|
appendChild() | Adds the new child node to the end of the node's child node list. |
cloneNode() | Clone node. |
compareDocumentPosition() | Compare the document positions 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 the key on the node. This object must first be set to this node by calling setUserData with the same key. |
hasAttributes() | If the node has attributes, return true, otherwise return false. |
hasChildNodes() | Returns true if the node has child nodes, otherwise returns false. |
insertBefore() | Insert a new child node before the existing child node. |
isDefaultNamespace(URI) | Returns whether the specified namespaceURI is default. |
isEqualNode() | Checks whether two nodes are equal. |
isSameNode() | Check 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 that matches the specified namespace URI. |
normalize() | Place all text nodes under the node (including attributes) into a "standard" format, in which only structures (such as elements, comments , processing instructions, CDATA sections, and entity references) to separate Text nodes, for example, there are neither adjacent Text nodes nor empty Text nodes. |
removeChild() | Delete child nodes. |
replaceChild() | Replace child node. |
setUserData(key,data,handler) | Associate the object to the key on the node. |