Interface Node

All Superinterfaces:
EventTarget, SearchContext
All Known Subinterfaces:
Attribute, Document, Element, FormControlElement, FormElement, FrameElement, ImageElement, InputElement, OptionElement, SelectElement, TextAreaElement

public interface Node extends EventTarget, SearchContext
A base DOM object providing access to the common DOM object properties and methods to manage the DOM node structure.
  • Method Details

    • document

      Document document()
      Returns the Document instance of this node.
      Throws:
      ObjectClosedException - when this node is closed
      Since:
      7.1
    • nodeName

      String nodeName()
      Returns a string that represents the node name in the UTF8 format.

      The returned values for different types of nodes are:

      Node type Returned value
      NodeType.ELEMENT_NODE The element tag name.

      For DOM trees which represent HTML documents, the returned value is always capitalized. The tag names of elements in an XML DOM tree are returned in the same case in which they're written in the original XML file.

      NodeType.ATTRIBUTE_NODE The attribute name
      NodeType.TEXT_NODE "#text"
      NodeType.C_DATA_SECTION_NODE "#cdata-section"
      The entity name
      NodeType.PROCESSING_INSTRUCTIONS_NODE The value of the target attribute
      NodeType.COMMENT_NODE "#comment"
      NodeType.DOCUMENT_NODE "#document"
      NodeType.DOCUMENT_TYPE_NODE The document type name, for example "html" for <!DOCTYPE HTML>
      NodeType.DOCUMENT_FRAGMENT_NODE "#document-fragment"
      Throws:
      ObjectClosedException - when this node is closed
    • nodeValue

      String nodeValue()
      Returns a string that represents the node value.

      The returned values for different types of nodes are:

      Node type Returned value
      NodeType.ELEMENT_NODE null
      NodeType.ATTRIBUTE_NODE The attribute value
      NodeType.TEXT_NODE The content of the text node
      NodeType.C_DATA_SECTION_NODE The content of the CDATA Section
      NodeType.PROCESSING_INSTRUCTIONS_NODE The entire node content excluding the target
      NodeType.COMMENT_NODE The content of the comment
      NodeType.DOCUMENT_NODE null
      NodeType.DOCUMENT_TYPE_NODE null
      NodeType.DOCUMENT_FRAGMENT_NODE null
      Throws:
      ObjectClosedException - when this instance is closed
    • nodeValue

      void nodeValue(String value)
      Updates the node value with the given new value.

      This method does nothing, if it is invoked for the node of one of the following types: NodeType.ELEMENT_NODE, NodeType.DOCUMENT_NODE, NodeType.DOCUMENT_TYPE_NODE, NodeType.DOCUMENT_FRAGMENT_NODE.

      Parameters:
      value - a new node value
      Throws:
      ObjectClosedException - when this node is closed
      See Also:
    • type

      NodeType type()
      Returns the node type.
      Throws:
      ObjectClosedException - when this node is closed
    • parent

      Optional<Node> parent()
      Returns an Optional that contains the parent of this node. If there is no such node, for example when this node is the document or it does not belong to the DOM tree, returns an empty Optional.
      Throws:
      ObjectClosedException - when this node is closed
    • children

      List<Node> children()
      Returns an immutable list of all children of this node.

      Please note, that this method should be invoked every time in case of need to retrieve an actual children list.

      Throws:
      ObjectClosedException - when this node is closed
    • nextSibling

      Optional<Node> nextSibling()
      Returns an Optional that contains the next node in the document tree if such a node exists, otherwise returns an empty Optional.
      Throws:
      ObjectClosedException - when this node is closed
    • previousSibling

      Optional<Node> previousSibling()
      Returns an Optional that contains the previous node in the document tree if such a node exists, otherwise returns an empty Optional.
      Throws:
      ObjectClosedException - when this node is closed
    • click

      void click()
      Simulates a click on the node.
      Throws:
      ObjectClosedException - when this node is closed
    • insertChild

      boolean insertChild(Node node, Node beforeNode)
      Inserts the given node before the given beforeNode as a child of the current node. The new node can be an existing node in the document, or you can create and insert a new node. If the node is existing node, it will be moved to a new location in the document.
      Parameters:
      node - the node to insert
      beforeNode - the node before which the node will be inserted
      Returns:
      true if the given node was successfully inserted
      Throws:
      ObjectClosedException - when this node is closed
    • replaceChild

      boolean replaceChild(Node newNode, Node oldNode)
      Replaces the given child oldNode of the current node with the given newNode. The new node can be an existing node in the document, or you can create and insert a new node. If the newNode is existing node, it will be moved to a new location in the document.
      Parameters:
      newNode - the new node to replace the oldNode
      oldNode - the existing node to be replaced
      Returns:
      true if the given oldNode was successfully replaced
      Throws:
      ObjectClosedException - when this node is closed
    • removeChild

      boolean removeChild(Node childNode)
      Removes the given childNode of the current node from the DOM. The removed childNode still exists, but is no longer part of the DOM. You can reuse the removed node later in your code via the childNode object reference.
      Parameters:
      childNode - the existing node to be removed
      Returns:
      true if the given node was successfully removed
      Throws:
      ObjectClosedException - when this node is closed
    • appendChild

      boolean appendChild(Node childNode)
      Adds the given node as a child of the current node to the end of its children list. The new node could be an existing node in the document, or you can create and add a new node. If the node is existing node, it will be moved to a new location in the document.
      Parameters:
      childNode - the node to append
      Returns:
      true if the given node was successfully inserted
      Throws:
      ObjectClosedException - when this node is closed
    • textContent

      String textContent()
      Returns the text content of the current node and its descendants.
      Throws:
      ObjectClosedException - when this node is closed
    • textContent

      void textContent(String textContent)
      Removes all the current node children and replaces them with a single text node with the given textContent.
      Parameters:
      textContent - the new text content of the current node
      Throws:
      ObjectClosedException - when this node is closed
    • evaluate

      XPathResult evaluate(String expression)
      Evaluates the given XPath expression for the node and returns the XPathResult of the XPathResultType.ANY type.
      Parameters:
      expression - a string representing the XPath to be evaluated
      Throws:
      IllegalArgumentException - when expression is empty
      XPathException - when this method failed to evaluate the given expression
      ObjectClosedException - when this node is closed
      See Also:
    • evaluate

      XPathResult evaluate(String expression, XPathResultType type)
      Evaluates the given XPath expression for the node and returns the XPathResult object of the given type.
      Parameters:
      expression - a string representing the XPath to be evaluated
      type - type of XPathResult to return
      Throws:
      IllegalArgumentException - when expression is empty or blank
      XPathException - when this method failed to evaluate the given expression and return a result of the given type
      ObjectClosedException - when this node is closed
      See Also:
    • xPath

      String xPath()
      Returns a string that represents XPath to the current Node or an empty string if it is not available.

      For the document() this method returns an empty string.

      Throws:
      ObjectClosedException - when this node is closed
      Since:
      7.2
    • compareDocumentPosition

      Set<DocumentPosition> compareDocumentPosition(Node otherNode)
      Compares position of the current node against another node in a DOM tree.
      Parameters:
      otherNode - the node to be compared to the current node
      Returns:
      a set of the positions of the node specified by the otherNode parameter relates to the position of the current node
      Throws:
      ObjectClosedException - when this node is closed
      Since:
      7.5
    • close

      void close()
      Closes this node.

      This method makes the underlying Blink node eligible for garbage collection, but does not guarantee that it will be destroyed. That is, if the node is still attached to the DOM tree, you can obtain it again through the DOM or JavaScript API.

      Use this method to make unused nodes garbage collectable when you create, attach and detach a large number of nodes to/from the DOM tree on the same web page without reloading, closing the browser, or navigating to another web page.

      All nodes are closed automatically when you perform a navigation, reload the web page, or close the browser.

      Since:
      7.32