- All Known Subinterfaces:
NonDocumentTypeChildNode
,ParentNode
- All Known Implementing Classes:
DOMDocument
,DOMElement
,HTMLDocument
,HTMLElement
DOM Node.
Use this interface or W3C's Node
at your convenience
(this one may save you a few type casts).
-
Field Summary
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
Method Summary
Modifier and TypeMethodDescriptionappendChild
(Node newChild) Adds the nodenewChild
to the end of the list of children of this node.Get the children of this node.Get the first child of this node.Get the last child of this node.Get the node immediately following this node in its parent's child list.Get theDOMDocument
object related to this node (for all nodes exceptDocumentType
, it is the document that created it), which is also the object that should be used to create new nodes for the document.Get the node immediately preceding this node in its parent's child list.boolean
Does this node have any child nodes ?insertBefore
(Node newChild, Node refChild) Inserts the nodenewChild
right before noderefChild
in the child node list.void
Removes all the children from this node, if any.removeChild
(Node oldChild) Removes the nodeoldChild
from the children of this node.replaceChild
(Node newChild, Node oldChild) Replaces the nodeoldChild
withnewChild
.Methods inherited from interface org.w3c.dom.Node
cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getFeature, getLocalName, getNamespaceURI, getNodeName, getNodeType, getNodeValue, getPrefix, getTextContent, getUserData, hasAttributes, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, setNodeValue, setPrefix, setTextContent, setUserData
-
Method Details
-
appendChild
Adds the nodenewChild
to the end of the list of children of this node. If thenewChild
is already in the tree, it is first removed.- Specified by:
appendChild
in interfaceNode
- Parameters:
newChild
- the node to append. If it is aDocumentFragment
object, the entire contents of the document fragment are moved into the child list of this node.- Returns:
- the appended node.
- Throws:
DOMException
- HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of thenewChild
node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocument
and the DOM application attempts to append a secondDocumentType
orElement
node.
WRONG_DOCUMENT_ERR: ifnewChild
was created from a different document than the one that created this node.
NOT_SUPPORTED_ERR: if this implementation does not support children of the type ofnewChild
at this node.
-
getChildNodes
DOMNodeList getChildNodes()Get the children of this node.- Specified by:
getChildNodes
in interfaceNode
- Returns:
- a
DOMNodeList
with the children of this node. If there are no children, an empty list is returned.
-
getFirstChild
DOMNode getFirstChild()Get the first child of this node.- Specified by:
getFirstChild
in interfaceNode
- Returns:
- the first child of this node,
null
if has no child nodes.
-
getLastChild
DOMNode getLastChild()Get the last child of this node.- Specified by:
getLastChild
in interfaceNode
- Returns:
- the last child of this node,
null
if has no child nodes.
-
getNextSibling
DOMNode getNextSibling()Get the node immediately following this node in its parent's child list.- Specified by:
getNextSibling
in interfaceNode
- Returns:
- the node immediately following this node in the child list, or
null
if none.
-
getOwnerDocument
DOMDocument getOwnerDocument()Get theDOMDocument
object related to this node (for all nodes exceptDocumentType
, it is the document that created it), which is also the object that should be used to create new nodes for the document.- Specified by:
getOwnerDocument
in interfaceCSSNode
- Specified by:
getOwnerDocument
in interfaceNode
- Returns:
- the
DOMDocument
object corresponding to this node. When this node is aDOMDocument
or aDocumentType
which was not added to anyDOMDocument
yet, this isnull
.
-
getParentNode
DOMNode getParentNode()- Specified by:
getParentNode
in interfaceNode
-
getPreviousSibling
DOMNode getPreviousSibling()Get the node immediately preceding this node in its parent's child list.- Specified by:
getPreviousSibling
in interfaceNode
- Returns:
- the node immediately preceding this node in the child list, or
null
if none.
-
hasChildNodes
boolean hasChildNodes()Does this node have any child nodes ?- Specified by:
hasChildNodes
in interfaceNode
- Returns:
true
if this node has child nodes,false
otherwise.
-
insertBefore
Inserts the nodenewChild
right before noderefChild
in the child node list.- If
refChild
isnull
,newChild
is appended at the end of the child list. - If the
newChild
is already in the tree, it is first removed. - Inserting a node before itself has no effect.
- Specified by:
insertBefore
in interfaceNode
- Parameters:
newChild
- the node to put at the child node list, beforerefChild
. If it is aDocumentFragment
object, the entire contents of the document fragment are inserted into the child list of this node.refChild
- the node before whichnewChild
must be inserted.- Returns:
- the inserted node.
- Throws:
DOMException
- HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of thenewChild
node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocument
and the DOM application attempts to append a secondDocumentType
orElement
node.
WRONG_DOCUMENT_ERR: ifnewChild
was created from a different document than the one that created this node.
NOT_FOUND_ERR: ifrefChild
is not a child of this node.
NOT_SUPPORTED_ERR: if this implementation does not support children of the type ofnewChild
at this node.
- If
-
removeAllChild
void removeAllChild()Removes all the children from this node, if any. -
removeChild
Removes the nodeoldChild
from the children of this node.- Specified by:
removeChild
in interfaceNode
- Parameters:
oldChild
- the node to remove.- Returns:
- the removed node.
- Throws:
DOMException
- NOT_FOUND_ERR: ifoldChild
is not a child of this node.
-
replaceChild
Replaces the nodeoldChild
withnewChild
. If thenewChild
is already in the tree, it is first removed.Replacing a node with itself has no effect.
- Specified by:
replaceChild
in interfaceNode
- Parameters:
newChild
- the node to put at the child node list, in place ofoldChild
. If it is aDocumentFragment
object, the entire contents of the document fragment are inserted into the child list of this node.oldChild
- the node being replaced.- Returns:
- the replaced (old) node.
- Throws:
DOMException
- HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of thenewChild
node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocument
and the DOM application attempts to append a secondDocumentType
orElement
node.
WRONG_DOCUMENT_ERR: ifnewChild
was created from a different document than the one that created this node.
NOT_FOUND_ERR: ifoldChild
is not a child of this node.
NOT_SUPPORTED_ERR: if this implementation does not support children of the type ofnewChild
at this node.
-