Interface DOMNode

All Superinterfaces:
CSSNode, Node
All Known Subinterfaces:
NonDocumentTypeChildNode, ParentNode
All Known Implementing Classes:
DOMDocument, DOMElement, HTMLDocument, HTMLElement

public interface DOMNode extends CSSNode
DOM Node.

Use this interface or W3C's Node at your convenience (this one may save you a few type casts).

  • Method Details

    • appendChild

      DOMNode appendChild(Node newChild) throws DOMException
      Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
      Specified by:
      appendChild in interface Node
      Parameters:
      newChild - the node to append. If it is a DocumentFragment 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 the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild 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 of newChild at this node.
    • getChildNodes

      DOMNodeList getChildNodes()
      Get the children of this node.
      Specified by:
      getChildNodes in interface Node
      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 interface Node
      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 interface Node
      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 interface Node
      Returns:
      the node immediately following this node in the child list, or null if none.
    • getOwnerDocument

      DOMDocument getOwnerDocument()
      Get the DOMDocument object related to this node (for all nodes except DocumentType, 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 interface CSSNode
      Specified by:
      getOwnerDocument in interface Node
      Returns:
      the DOMDocument object corresponding to this node. When this node is a DOMDocument or a DocumentType which was not added to any DOMDocument yet, this is null.
    • getParentNode

      DOMNode getParentNode()
      Specified by:
      getParentNode in interface Node
    • getPreviousSibling

      DOMNode getPreviousSibling()
      Get the node immediately preceding this node in its parent's child list.
      Specified by:
      getPreviousSibling in interface Node
      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 interface Node
      Returns:
      true if this node has child nodes, false otherwise.
    • insertBefore

      DOMNode insertBefore(Node newChild, Node refChild) throws DOMException
      Inserts the node newChild right before node refChild in the child node list.
      • If refChild is null, 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 interface Node
      Parameters:
      newChild - the node to put at the child node list, before refChild. If it is a DocumentFragment object, the entire contents of the document fragment are inserted into the child list of this node.
      refChild - the node before which newChild 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 the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_FOUND_ERR: if refChild is not a child of this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • removeChild

      DOMNode removeChild(Node oldChild) throws DOMException
      Removes the node oldChild from the children of this node.
      Specified by:
      removeChild in interface Node
      Parameters:
      oldChild - the node to remove.
      Returns:
      the removed node.
      Throws:
      DOMException - NOT_FOUND_ERR: if oldChild is not a child of this node.
    • replaceChild

      DOMNode replaceChild(Node newChild, Node oldChild) throws DOMException
      Replaces the node oldChild with newChild. If the newChild is already in the tree, it is first removed.

      Replacing a node with itself has no effect.

      Specified by:
      replaceChild in interface Node
      Parameters:
      newChild - the node to put at the child node list, in place of oldChild. If it is a DocumentFragment 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 the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_FOUND_ERR: if oldChild is not a child of this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.