Skip to main content

XML DOM: Node Object

The Node object represents a single node in the document tree.

A node can be any type that is an attribute node, a text node or any other node. The attributes nodeName, nodeValue and attributes are included as a mechanism to get at node information without casting down to the specific derived interface.

Properties

PropertyDescription
attributesThis is of type NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
baseURIReturns a string representing the base URL of the document containing the Node
childNodesReturns a NodeList of child nodes for a node
firstChildReturns the first child of a node
lastChildReturns the last child of a node
nextSiblingReturns the node immediately following a node
nodeNameReturns the name of a node, depending on its type
nodeTypeReturns the type of a node
nodeValueSets or returns the value of a node, depending on its type
ownerDocumentReturns the root element (document object) for a node
parentNodeReturns the parent node of a node
prefixSets or returns the namespace prefix of a node
previousSiblingReturns the node immediately before a node
textContentSets or returns the textual content of a node and its descendants

Node Types

NameValue
ELEMENT_NODE1
ATTRIBUTE_NODE2
TEXT_NODE3
CDATA_SECTION_NODE4
PROCESSING_INSTRUCTION_NODE7
COMMENT_NODE8
DOCUMENT_NODE9
DOCUMENT_TYPE_NODE10
DOCUMENT_FRAGMENT_NODE11

Methods

MethodDescription
appendChild(Node newChild)Appends a new child node to the end of the list of children of a node
cloneNode(boolean deep)Create a duplicate node, when overridden in a derived class. It returns the duplicated node.
compareDocumentPosition(Node other)Compares the placement of two nodes in the DOM hierarchy (document)
getFeature(DOMString feature, DOMString version)Returns a DOM object which implements the specialized APIs of the specified feature and version
getUserData(DOMString key)Returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key
hasAttributes()Returns true if the specified node has any attributes, otherwise false
hasChildNodes()Returns true if the specified node has any child nodes, otherwise false
insertBefore(Node newChild, Node refChild)Inserts a new child node before an existing child node
isDefaultNamespace(DOMString namespaceURI)Returns whether the specified namespaceURI is the default
isEqualNode(Node arg)Tests whether two nodes are equal
isSameNode(Node other)Tests whether the two nodes are the same node
isSupported(DOMString feature, DOMString version)Returns whether the specified DOM module is supported by the current node. Returns true if the specified feature is supported on this node, false otherwise.
lookupNamespaceURI(DOMString prefix)Returns the namespace URI associated with a given prefix
lookupPrefix(DOMString namespaceURI)Returns the prefix associated with a given namespace URI
normalize()Puts all Text nodes underneath a node (including attribute nodes) 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(Node oldChild)Removes a specified child node from the current node
replaceChild(Node newChild, Node oldChild)Replaces a child node with a new node
setUserData(key,data,handler)Associates an object to a key on a node