XML DOM - Node
Object
Node Object
The Node object represents a single node in the document tree.
The node can be an element node, attribute node, text node, or any other node type mentioned in the Node Types chapter.
Note that although all objects inherit 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 might result in 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. |
firstChild | Returns the first child node. |
lastChild | Returns the last child node. |
localName | Returns the local part of the node 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 the node, depending on its type. |
ownerDocument | Returns the root element (document object) of the node. |
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 list of children. |
cloneNode() | Clones the node. |
compareDocumentPosition() | Compares the document position of two nodes. |
getFeature(feature, version) | Returns a DOM object which can execute specialized API with specified features and version. |
getUserData(key) | Returns the object associated with the key on the node. This object must first be set on this node by calling setUserData with the same key. |
hasAttributes() | Returns true if the node has any attributes, otherwise false. |
hasChildNodes() | Returns true if the node has any 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 if two nodes are equal. |
isSameNode() | Checks if 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 this node (including attributes) into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. |
removeChild() | Removes a child node. |
replaceChild() | Replaces a child node. |
setUserData(key, data, handler) | Associates an object to a key on the node. |