- 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 nodenewChildto 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 theDOMDocumentobject 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.booleanDoes this node have any child nodes ?insertBefore(Node newChild, Node refChild) Inserts the nodenewChildright before noderefChildin the child node list.voidRemoves all the children from this node, if any.removeChild(Node oldChild) Removes the nodeoldChildfrom the children of this node.replaceChild(Node newChild, Node oldChild) Replaces the nodeoldChildwithnewChild.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 nodenewChildto the end of the list of children of this node. If thenewChildis already in the tree, it is first removed.- Specified by:
appendChildin interfaceNode- Parameters:
newChild- the node to append. If it is aDocumentFragmentobject, 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 thenewChildnode, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocumentand the DOM application attempts to append a secondDocumentTypeorElementnode.
WRONG_DOCUMENT_ERR: ifnewChildwas 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 ofnewChildat this node.
-
getChildNodes
DOMNodeList getChildNodes()Get the children of this node.- Specified by:
getChildNodesin interfaceNode- Returns:
- a
DOMNodeListwith 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:
getFirstChildin interfaceNode- Returns:
- the first child of this node,
nullif has no child nodes.
-
getLastChild
DOMNode getLastChild()Get the last child of this node.- Specified by:
getLastChildin interfaceNode- Returns:
- the last child of this node,
nullif has no child nodes.
-
getNextSibling
DOMNode getNextSibling()Get the node immediately following this node in its parent's child list.- Specified by:
getNextSiblingin interfaceNode- Returns:
- the node immediately following this node in the child list, or
nullif none.
-
getOwnerDocument
DOMDocument getOwnerDocument()Get theDOMDocumentobject 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:
getOwnerDocumentin interfaceCSSNode- Specified by:
getOwnerDocumentin interfaceNode- Returns:
- the
DOMDocumentobject corresponding to this node. When this node is aDOMDocumentor aDocumentTypewhich was not added to anyDOMDocumentyet, this isnull.
-
getParentNode
DOMNode getParentNode()- Specified by:
getParentNodein interfaceNode
-
getPreviousSibling
DOMNode getPreviousSibling()Get the node immediately preceding this node in its parent's child list.- Specified by:
getPreviousSiblingin interfaceNode- Returns:
- the node immediately preceding this node in the child list, or
nullif none.
-
hasChildNodes
boolean hasChildNodes()Does this node have any child nodes ?- Specified by:
hasChildNodesin interfaceNode- Returns:
trueif this node has child nodes,falseotherwise.
-
insertBefore
Inserts the nodenewChildright before noderefChildin the child node list.- If
refChildisnull,newChildis appended at the end of the child list. - If the
newChildis already in the tree, it is first removed. - Inserting a node before itself has no effect.
- Specified by:
insertBeforein interfaceNode- Parameters:
newChild- the node to put at the child node list, beforerefChild. If it is aDocumentFragmentobject, the entire contents of the document fragment are inserted into the child list of this node.refChild- the node before whichnewChildmust 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 thenewChildnode, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocumentand the DOM application attempts to append a secondDocumentTypeorElementnode.
WRONG_DOCUMENT_ERR: ifnewChildwas created from a different document than the one that created this node.
NOT_FOUND_ERR: ifrefChildis not a child of this node.
NOT_SUPPORTED_ERR: if this implementation does not support children of the type ofnewChildat this node.
- If
-
removeAllChild
void removeAllChild()Removes all the children from this node, if any. -
removeChild
Removes the nodeoldChildfrom the children of this node.- Specified by:
removeChildin interfaceNode- Parameters:
oldChild- the node to remove.- Returns:
- the removed node.
- Throws:
DOMException- NOT_FOUND_ERR: ifoldChildis not a child of this node.
-
replaceChild
Replaces the nodeoldChildwithnewChild. If thenewChildis already in the tree, it is first removed.Replacing a node with itself has no effect.
- Specified by:
replaceChildin interfaceNode- Parameters:
newChild- the node to put at the child node list, in place ofoldChild. If it is aDocumentFragmentobject, 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 thenewChildnode, or if the node to append is one of this node's ancestors or this node itself, or if this node is of typeDocumentand the DOM application attempts to append a secondDocumentTypeorElementnode.
WRONG_DOCUMENT_ERR: ifnewChildwas created from a different document than the one that created this node.
NOT_FOUND_ERR: ifoldChildis not a child of this node.
NOT_SUPPORTED_ERR: if this implementation does not support children of the type ofnewChildat this node.
-