Node

public interface Node
Known Indirect Subclasses

The Node interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing the Node interface expose methods for dealing with children, not all objects implementing the Node interface may have children. For example, Text nodes may not have children, and adding children to such nodes results in a DOMException being raised.

The attributes nodeName, nodeValue and attributes are included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specific nodeType (e.g., nodeValue for an Element or attributes for a Comment ), this returns null. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

The values of nodeName, nodeValue, and attributes vary according to the node type as follows:

Interface nodeName nodeValue attributes
Attr same as Attr.name same as Attr.value null
CDATASection "#cdata-section" same as CharacterData.data, the content of the CDATA Section null
Comment "#comment" same as CharacterData.data, the content of the comment null
Document "#document" null null
DocumentFragment "#document-fragment" null null
DocumentType same as DocumentType.name null null
Element same as Element.tagName null NamedNodeMap
Entity entity name null null
EntityReference name of entity referenced null null
Notation notation name null null
ProcessingInstruction same as ProcessingInstruction.target same as ProcessingInstruction.data null
Text "#text" same as CharacterData.data, the content of the text node null

See also the Document Object Model (DOM) Level 3 Core Specification.

Constant Summary

short ATTRIBUTE_NODE The node is an Attr.
short CDATA_SECTION_NODE The node is a CDATASection.
short COMMENT_NODE The node is a Comment.
short DOCUMENT_FRAGMENT_NODE The node is a DocumentFragment.
short DOCUMENT_NODE The node is a Document.
short DOCUMENT_POSITION_CONTAINED_BY The node is contained by the reference node.
short DOCUMENT_POSITION_CONTAINS The node contains the reference node.
short DOCUMENT_POSITION_DISCONNECTED The two nodes are disconnected.
short DOCUMENT_POSITION_FOLLOWING The node follows the reference node.
short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC The determination of preceding versus following is implementation-specific.
short DOCUMENT_POSITION_PRECEDING The second node precedes the reference node.
short DOCUMENT_TYPE_NODE The node is a DocumentType.
short ELEMENT_NODE The node is an Element.
short ENTITY_NODE The node is an Entity.
short ENTITY_REFERENCE_NODE The node is an EntityReference.
short NOTATION_NODE The node is a Notation.
short PROCESSING_INSTRUCTION_NODE The node is a ProcessingInstruction.
short TEXT_NODE The node is a Text node.

Public Method Summary

abstract Node
appendChild(Node newChild)
Adds the node newChild to the end of the list of children of this node.
abstract Node
cloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
abstract short
compareDocumentPosition(Node other)
Compares the reference node, i.e.
abstract NamedNodeMap
getAttributes()
A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
abstract String
getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.
abstract NodeList
getChildNodes()
A NodeList that contains all children of this node.
abstract Object
getFeature(String feature, String version)
This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in .
abstract Node
getFirstChild()
The first child of this node.
abstract Node
getLastChild()
The last child of this node.
abstract String
getLocalName()
Returns the local part of the qualified name of this node.
abstract String
getNamespaceURI()
The namespace URI of this node, or null if it is unspecified (see ).
abstract Node
getNextSibling()
The node immediately following this node.
abstract String
getNodeName()
The name of this node, depending on its type; see the table above.
abstract short
getNodeType()
A code representing the type of the underlying object, as defined above.
abstract String
getNodeValue()
The value of this node, depending on its type; see the table above.
abstract