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.
| Modifier and Type | Field and Description |
|---|---|
| public static final short | ATTRIBUTE_NODE
The node is an |
| public static final short | CDATA_SECTION_NODE
The node is a |
| public static final short | COMMENT_NODE
The node is a |
| public static final short | DOCUMENT_FRAGMENT_NODE
The node is a |
| public static final short | DOCUMENT_NODE
The node is a |
| public static final short | DOCUMENT_POSITION_CONTAINED_BY
The node is contained by the reference node. |
| public static final short | DOCUMENT_POSITION_CONTAINS
The node contains the reference node. |
| public static final short | DOCUMENT_POSITION_DISCONNECTED
The two nodes are disconnected. |
| public static final short | DOCUMENT_POSITION_FOLLOWING
The node follows the reference node. |
| public static final short | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
The determination of preceding versus following is implementation-specific. |
| public static final short | DOCUMENT_POSITION_PRECEDING
The second node precedes the reference node. |
| public static final short | DOCUMENT_TYPE_NODE
The node is a |
| public static final short | ELEMENT_NODE
The node is an |
| public static final short | ENTITY_NODE
The node is an |
| public static final short | ENTITY_REFERENCE_NODE
The node is an |
| public static final short | NOTATION_NODE
The node is a |
| public static final short | PROCESSING_INSTRUCTION_NODE
The node is a |
| public static final short | TEXT_NODE
The node is a |
| Modifier and Type | Method and Description |
|---|---|
| public Node | Returns: The node added.The node to add.If it is a
newChild)DocumentFragment object, the entire contents of the
document fragment are moved into the child list of this nodeAdds the node |
| public Node | Returns: The duplicate node.If deep)true, recursively clone the subtree under
the specified node; if false, clone only the node
itself (and its attributes, if it is an Element).Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. |
| public short | Returns: Returns how the node is positioned relatively to the reference node.The node to compare against the reference node. other)Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order. |
| public NamedNodeMap | getAttributes()
A |
| public String | getBaseURI()
The absolute base URI of this node or |
| public NodeList | |
| public Object | Returns: Returns an object which implements the specialized APIs of the specified feature and version, if any, ornull if
there is no object which implements interfaces associated with that
feature. If the DOMObject returned by this method
implements the Node interface, it must delegate to the
primary core Node and not return results inconsistent
with the primary core Node such as attributes,
childNodes, etc.The name of the feature requested. Note that any plus
sign "+" prepended to the name of the feature will be ignored since
it is not significant in the context of this method. feature, String This is the version number of the feature to test. version)This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in . |
| public Node | |
| public Node | |
| public String | |
| public String | |
| public Node | |
| public String | |
| public short | |
| public String | |
| public Document | |
| public Node | |
| public String | |
| public Node | |
| public String | |
| public Object | Returns: Returns theDOMUserData associated to the given
key on this node, or null if there was none.The key the object is associated to. key)Retrieves the object associated to a key on a this node. |
| public boolean | Returns: Returnstrue if this node has any attributes,
false otherwise.Returns whether this node (if it is an element) has any attributes. |
| public boolean | Returns: Returnstrue if this node has any children,
false otherwise.Returns whether this node has any children. |
| public Node | Returns: The node being inserted.The node to insert. newChild, Node The reference node, i.e., the node before which the
new node must be inserted. refChild)Inserts the node |
| public boolean | Returns: Returnstrue if the specified
namespaceURI is the default namespace,
false otherwise.The namespace URI to look for. namespaceURI)This method checks if the specified |
| public boolean | Returns: Returnstrue if the nodes are equal,
false otherwise.The node to compare equality with. arg)Tests whether two nodes are equal. |
| public boolean | Returns: Returnstrue if the nodes are the same,
false otherwise.The node to test against. other)Returns whether this node is the same node as the given one. |
| public boolean | Returns: Returnstrue if the specified feature is
supported on this node, false otherwise.The name of the feature to test. feature, String This is the version number of the feature to test. version)Tests whether the DOM implementation implements a specific feature and that feature is supported by this node, as specified in . |
| public String | Returns: Returns the associated namespace URI ornull if
none is found.The prefix to look for. If this parameter is
prefix)null, the method will return the default namespace URI
if any.Look up the namespace URI associated to the given prefix, starting from this node. |
| public String | Returns: Returns an associated namespace prefix if found ornull if none is found. If more than one prefix are
associated to the namespace prefix, the returned namespace prefix
is implementation dependent.The namespace URI to look for. namespaceURI)Look up the prefix associated to the given namespace URI, starting from this node. |
| public void | normalize()
Puts all |
| public Node | Returns: The node removed.The node being removed. oldChild)Removes the child node indicated by |
| public Node | Returns: The node replaced.The new node to put in the child list. newChild, Node The node being replaced in the list. oldChild)Replaces the child node |
| public void | |
| public void | |
| public void | setTextContent(String textContent)
This attribute returns the text content of this node and its descendants. |
| public Object | Returns: Returns theDOMUserData previously associated to
the given key on this node, or null if there was none.The key to associate the object to. key, Object The object to associate to the given key, or
data, UserDataHandler null to remove any existing association to that key.The handler to associate to that key, or
handler)null.Associate an object to a key on this node. |
| ATTRIBUTE_NODE | back to summary |
|---|---|
| public static final short ATTRIBUTE_NODE The node is an | |
| CDATA_SECTION_NODE | back to summary |
|---|---|
| public static final short CDATA_SECTION_NODE The node is a | |
| COMMENT_NODE | back to summary |
|---|---|
| public static final short COMMENT_NODE The node is a | |
| DOCUMENT_FRAGMENT_NODE | back to summary |
|---|---|
| public static final short DOCUMENT_FRAGMENT_NODE The node is a | |
| DOCUMENT_NODE | back to summary |
|---|---|
| public static final short DOCUMENT_NODE The node is a | |
| DOCUMENT_POSITION_CONTAINED_BY | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_CONTAINED_BY The node is contained by the reference node. A node which is contained is always following, too. | |
| DOCUMENT_POSITION_CONTAINS | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_CONTAINS The node contains the reference node. A node which contains is always preceding, too. | |
| DOCUMENT_POSITION_DISCONNECTED | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_DISCONNECTED The two nodes are disconnected. Order between disconnected nodes is always implementation-specific. | |
| DOCUMENT_POSITION_FOLLOWING | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_FOLLOWING The node follows the reference node. | |
| DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC The determination of preceding versus following is implementation-specific. | |
| DOCUMENT_POSITION_PRECEDING | back to summary |
|---|---|
| public static final short DOCUMENT_POSITION_PRECEDING The second node precedes the reference node. | |
| DOCUMENT_TYPE_NODE | back to summary |
|---|---|
| public static final short DOCUMENT_TYPE_NODE The node is a | |
| ELEMENT_NODE | back to summary |
|---|---|
| public static final short ELEMENT_NODE The node is an | |
| ENTITY_NODE | back to summary |
|---|---|
| public static final short ENTITY_NODE The node is an | |
| ENTITY_REFERENCE_NODE | back to summary |
|---|---|
| public static final short ENTITY_REFERENCE_NODE The node is an | |
| NOTATION_NODE | back to summary |
|---|---|
| public static final short NOTATION_NODE The node is a | |
| PROCESSING_INSTRUCTION_NODE | back to summary |
|---|---|
| public static final short PROCESSING_INSTRUCTION_NODE The node is a | |
| TEXT_NODE | back to summary |
|---|---|
| public static final short TEXT_NODE The node is a | |
| appendChild | back to summary |
|---|---|
| public Node appendChild(Node newChild) throws DOMException Adds the node
| |
| cloneNode | back to summary |
|---|---|
| public Node cloneNode(boolean deep) Returns a duplicate of this node, i.e., serves as a generic copy
constructor for nodes. The duplicate node has no parent (
| |
| compareDocumentPosition | back to summary |
|---|---|
| public short compareDocumentPosition(Node other) throws DOMException Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order.
| |
| getAttributes | back to summary |
|---|---|
| public NamedNodeMap getAttributes() A | |
| getBaseURI | back to summary |
|---|---|
| public String getBaseURI() The absolute base URI of this node or
| |
| getChildNodes | back to summary |
|---|---|
| public NodeList getChildNodes() A | |
| getFeature | back to summary |
|---|---|
| public 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 . The specialized object may also be obtained by using
binding-specific casting methods but is not necessarily expected to,
as discussed in . This method also allow the implementation to
provide specialized objects which do not support the
| |
| getFirstChild | back to summary |
|---|---|
| public Node getFirstChild() The first child of this node. If there is no such node, this returns
| |
| getLastChild | back to summary |
|---|---|
| public Node getLastChild() The last child of this node. If there is no such node, this returns
| |
| getLocalName | back to summary |
|---|---|
| public String getLocalName() Returns the local part of the qualified name of this node.
| |
| getNamespaceURI | back to summary |
|---|---|
| public String getNamespaceURI() The namespace URI of this node, or Note Per the Namespaces in XML Specification [XML Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.
| |
| getNextSibling | back to summary |
|---|---|
| public Node getNextSibling() The node immediately following this node. If there is no such node,
this returns | |
| getNodeName | back to summary |
|---|---|
| public String getNodeName() The name of this node, depending on its type; see the table above. | |
| getNodeType | back to summary |
|---|---|
| public short getNodeType() A code representing the type of the underlying object, as defined above. | |
| getNodeValue | back to summary |
|---|---|
| public String getNodeValue() throws DOMException The value of this node, depending on its type; see the table above.
When it is defined to be
| |
| getOwnerDocument | back to summary |
|---|---|
| public Document getOwnerDocument() The
| |
| getParentNode | back to summary |
|---|---|
| public Node getParentNode() The parent of this node. All nodes, except | |
| getPrefix | back to summary |
|---|---|
| public String getPrefix() The namespace prefix of this node, or
| |
| getPreviousSibling | back to summary |
|---|---|
| public Node getPreviousSibling() The node immediately preceding this node. If there is no such node,
this returns | |
| getTextContent | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public String getTextContent() throws DOMException This attribute returns the text content of this node and its
descendants. When it is defined to be
| |||||||||
| getUserData | back to summary |
|---|---|
| public Object getUserData(String key) Retrieves the object associated to a key on a this node. The object
must first have been set to this node by calling
| |
| hasAttributes | back to summary |
|---|---|
| public boolean hasAttributes() Returns whether this node (if it is an element) has any attributes.
| |
| hasChildNodes | back to summary |
|---|---|
| public boolean hasChildNodes() Returns whether this node has any children.
| |
| insertBefore | back to summary |
|---|---|
| public Node insertBefore(Node newChild, Node refChild) throws DOMException Inserts the node Note Inserting a node before itself is implementation dependent.
| |
| isDefaultNamespace | back to summary |
|---|---|
| public boolean isDefaultNamespace(String namespaceURI) This method checks if the specified
| |
| isEqualNode | back to summary |
|---|---|
| public boolean isEqualNode(Node arg) Tests whether two nodes are equal.
For two DocumentType nodes to be equal, the following
conditions must also be satisfied:
On the other hand, the following do not affect equality: the ownerDocument, baseURI, and
parentNode attributes, the specified
attribute for Attr nodes, the schemaTypeInfo
attribute for Attr and Element nodes, the
Text.isElementContentWhitespace attribute for
Text nodes, as well as any user data or event listeners
registered on the nodes.Note As a general rule, anything not mentioned in the description above is not significant in consideration of equality checking. Note that future versions of this specification may take into account more attributes and implementations conform to this specification are expected to be updated accordingly.
| |
| isSameNode | back to summary |
|---|---|
| public boolean isSameNode(Node other) Returns whether this node is the same node as the given one.
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(String feature, String version) Tests whether the DOM implementation implements a specific feature and that feature is supported by this node, as specified in . | |
| lookupNamespaceURI | back to summary |
|---|---|
| public String lookupNamespaceURI(String prefix) Look up the namespace URI associated to the given prefix, starting from
this node.
| |
| lookupPrefix | back to summary |
|---|---|
| public String lookupPrefix(String namespaceURI) Look up the prefix associated to the given namespace URI, starting from
this node. The default namespace declarations are ignored by this
method.
| |
| normalize | back to summary |
|---|---|
| public void normalize() Puts all Note In cases where the document contains
| |
| removeChild | back to summary |
|---|---|
| public Node removeChild(Node oldChild) throws DOMException Removes the child node indicated by
| |
| replaceChild | back to summary |
|---|---|
| public Node replaceChild(Node newChild, Node oldChild) throws DOMException Replaces the child node Note Replacing a node with itself is implementation dependent.
| |
| setNodeValue | back to summary |
|---|---|
| public void setNodeValue(String nodeValue) throws DOMException The value of this node, depending on its type; see the table above.
When it is defined to be
| |
| setPrefix | back to summary |
|---|---|
| public void setPrefix(String prefix) throws DOMException The namespace prefix of this node, or
| |
| setTextContent | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public void setTextContent(String textContent) throws DOMException This attribute returns the text content of this node and its
descendants. When it is defined to be
| |||||||||
| setUserData | back to summary |
|---|---|
| public Object setUserData(String key, Object data, UserDataHandler handler) Associate an object to a key on this node. The object can later be
retrieved from this node by calling
| |