Class DomNode

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PROPERTY_ELEMENT
      The name of the "element" property.
      static java.lang.String READY_STATE_COMPLETE
      A ready state constant for IE (state 5).
      static java.lang.String READY_STATE_INTERACTIVE
      A ready state constant for IE (state 4).
      static java.lang.String READY_STATE_LOADED
      A ready state constant for IE (state 3).
      static java.lang.String READY_STATE_LOADING
      A ready state constant for IE (state 2).
      static java.lang.String READY_STATE_UNINITIALIZED
      A ready state constant for IE (state 1).
      • 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
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DomNode​(SgmlPage page)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCharacterDataChangeListener​(CharacterDataChangeListener listener)
      Adds a CharacterDataChangeListener to the listener list.
      void addDomChangeListener​(DomChangeListener listener)
      Adds a DomChangeListener to the listener list.
      DomNode appendChild​(org.w3c.dom.Node node)
      java.lang.String asNormalizedText()
      Returns a normalized textual representation of this element that represents what would be visible to the user if this page was shown in a web browser.
      java.lang.String asXml()
      Returns a string representation of the XML document from this element and all it's children (recursively).
      protected void basicRemove()
      Cuts off all relationships this node has with siblings and parents.
      protected void checkChildHierarchy​(org.w3c.dom.Node newChild)
      Check for insertion errors for a new child node.
      DomNode cloneNode​(boolean deep)
      DomElement closest​(java.lang.String selectorString)  
      short compareDocumentPosition​(org.w3c.dom.Node other)
      protected void detach()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Detach this node from all relationships with other nodes.
      protected void fireCharacterDataChanged​(CharacterDataChangeEvent event)
      Support for reporting Character Data changes.
      protected void fireNodeAdded​(DomChangeEvent event)
      Support for reporting DOM changes.
      protected void fireNodeDeleted​(DomChangeEvent event)
      Support for reporting DOM changes.
      java.util.List<org.w3c.dom.Node> getAncestors()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Gets the ancestors of the node.
      org.w3c.dom.NamedNodeMap getAttributes()
      java.lang.String getBaseURI()
      <T> java.util.List<T> getByXPath​(java.lang.String xpathExpr)
      Evaluates the specified XPath expression from this node, returning the matching elements.
      java.util.List<?> getByXPath​(java.lang.String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
      Evaluates the specified XPath expression from this node, returning the matching elements.
      java.lang.String getCanonicalXPath()
      Returns the canonical XPath expression which identifies this node, for instance "/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]".
      DomNodeList<DomNode> getChildNodes()
      java.lang.Iterable<DomNode> getChildren()  
      java.lang.Iterable<DomNode> getDescendants()
      Returns an Iterable that will recursively iterate over all of this node's descendants, including DomText elements, DomComment elements, etc.
      java.lang.Iterable<DomElement> getDomElementDescendants()
      Returns an Iterable that will recursively iterate over all of this node's DomElement descendants.
      int getEndColumnNumber()
      Returns the column number in the source page where the DOM node ends.
      int getEndLineNumber()
      Returns the line number in the source page where the DOM node ends.
      java.lang.Object getFeature​(java.lang.String feature, java.lang.String version)
      Not yet implemented.
      <X> X getFirstByXPath​(java.lang.String xpathExpr)
      Evaluates the specified XPath expression from this node, returning the first matching element, or null if no node matches the specified XPath expression.
      <X> X getFirstByXPath​(java.lang.String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
      Evaluates the specified XPath expression from this node, returning the first matching element, or null if no node matches the specified XPath expression.
      DomNode getFirstChild()
      java.lang.Iterable<HtmlElement> getHtmlElementDescendants()
      Returns an Iterable that will recursively iterate over all of this node's HtmlElement descendants.
      HtmlPage getHtmlPageOrNull()
      Returns the page that contains this node.
      int getIndex()
      Returns this node's index within its parent's child nodes (zero-based).
      DomNode getLastChild()
      java.lang.String getLocalName()
      java.lang.String getNamespaceURI()
      DomElement getNextElementSibling()
      Returns the next sibling element node of this element.
      DomNode getNextSibling()
      java.lang.String getNodeValue()
      org.w3c.dom.Document getOwnerDocument()
      SgmlPage getPage()
      Returns the page that contains this node.
      DomNode getParentNode()
      java.lang.String getPrefix()
      DomElement getPreviousElementSibling()
      Returns the previous sibling element node of this element.
      DomNode getPreviousSibling()
      java.lang.String getReadyState()
      Returns this node's ready state (IE only).
      <T extends org.htmlunit.javascript.HtmlUnitScriptable>
      T
      getScriptableObject()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      protected org.htmlunit.cssparser.parser.selector.SelectorList getSelectorList​(java.lang.String selectors, WebClient webClient)
      Returns the SelectorList.
      int getStartColumnNumber()
      Returns the column number in the source page where the DOM node starts.
      int getStartLineNumber()
      Returns the line number in the source page where the DOM node starts.
      java.lang.String getTextContent()
      java.lang.Object getUserData​(java.lang.String key)
      java.lang.String getVisibleText()
      Returns a textual representation of this element in the same way as the selenium/WebDriver WebElement#getText() property does.
      see get-element-text and dfn-bot-dom-getvisibletext Note: this is different from asNormalizedText()
      boolean handles​(org.htmlunit.javascript.host.event.Event event)
      Indicates if the provided event can be applied to this node.
      boolean hasAttributes()
      boolean hasChildNodes()
      boolean hasFeature​(BrowserVersionFeatures feature)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Helper for a common call sequence.
      void insertBefore​(DomNode newNode)
      Inserts the specified node as a new child node before this node into the child relationship this node is a part of.
      org.w3c.dom.Node insertBefore​(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
      boolean isAncestorOf​(DomNode node)
      Returns true if this node is an ancestor of the specified node.
      boolean isAncestorOfAny​(DomNode... nodes)
      Returns true if this node is an ancestor of the specified nodes.
      boolean isAttachedToPage()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Indicates if this node is currently attached to the page.
      boolean isDefaultNamespace​(java.lang.String namespaceURI)
      Not yet implemented.
      boolean isDisplayed()
      Returns true if this node is displayed and can be visible to the user (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).
      boolean isEqualNode​(org.w3c.dom.Node arg)
      Not yet implemented.
      boolean isSameNode​(org.w3c.dom.Node other)
      boolean isSupported​(java.lang.String namespace, java.lang.String featureName)
      Not yet implemented.
      java.lang.String lookupNamespaceURI​(java.lang.String prefix)
      Not yet implemented.
      java.lang.String lookupPrefix​(java.lang.String namespaceURI)
      Not yet implemented.
      boolean mayBeDisplayed()
      Returns true if nodes of this type can ever be displayed, false otherwise.
      void normalize()
      protected void notifyIncorrectness​(java.lang.String message)
      Notifies the registered IncorrectnessListener of something that is not fully correct.
      protected void onAddedToDocumentFragment()
      Lifecycle method invoked whenever a node is added to a document fragment.
      protected void onAddedToPage()
      Lifecycle method invoked whenever a node is added to a page.
      void onAllChildrenAddedToPage​(boolean postponed)
      Lifecycle method invoked after a node and all its children have been added to a page, during parsing of the HTML.
      void parseHtmlSnippet​(java.lang.String source)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Parses the specified HTML source code, appending the resulting content at the specified target location.
      protected void printChildrenAsXml​(java.lang.String indent, java.io.PrintWriter printWriter)
      Recursively writes the XML data for the node tree starting at node.
      protected void printXml​(java.lang.String indent, java.io.PrintWriter printWriter)
      Recursively writes the XML data for the node tree starting at node.
      void processImportNode​(org.htmlunit.javascript.host.dom.Document doc)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Lifecycle method to support special processing for js method importNode.
      <N extends DomNode>
      N
      querySelector​(java.lang.String selectors)
      Returns the first element within the document that matches the specified group of selectors.
      DomNodeList<DomNode> querySelectorAll​(java.lang.String selectors)
      Retrieves all element nodes from descendants of the starting element node that match any selector within the supplied selector strings.
      void quietlyRemoveAndMoveChildrenTo​(DomNode destination)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Quietly removes this node and moves its children to the specified destination.
      void remove()
      Removes this node from all relationships with other nodes.
      void removeAllChildren()
      Removes all of this node's children.
      void removeCharacterDataChangeListener​(CharacterDataChangeListener listener)
      Removes a CharacterDataChangeListener from the listener list.
      org.w3c.dom.Node removeChild​(org.w3c.dom.Node child)
      void removeDomChangeListener​(DomChangeListener listener)
      Removes a DomChangeListener from the listener list.
      void replace​(DomNode newNode)
      Replaces this node with another node.
      org.w3c.dom.Node replaceChild​(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
      void setEndLocation​(int endLineNumber, int endColumnNumber)
      Sets the line and column numbers in the source page where the DOM node ends.
      protected void setParentNode​(DomNode parent)
      Sets the parent node.
      void setReadyState​(java.lang.String state)
      Sets this node's ready state (IE only).
      void setScriptableObject​(org.htmlunit.javascript.HtmlUnitScriptable scriptObject)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Sets the JavaScript object that corresponds to this node.
      void setStartLocation​(int startLineNumber, int startColumnNumber)
      Sets the line and column numbers in the source page where the DOM node starts.
      void setTextContent​(java.lang.String textContent)
      java.lang.Object setUserData​(java.lang.String key, java.lang.Object data, org.w3c.dom.UserDataHandler handler)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.w3c.dom.Node

        getNodeName, getNodeType, setNodeValue, setPrefix
    • Field Detail

      • READY_STATE_UNINITIALIZED

        public static final java.lang.String READY_STATE_UNINITIALIZED
        A ready state constant for IE (state 1).
        See Also:
        Constant Field Values
      • READY_STATE_LOADING

        public static final java.lang.String READY_STATE_LOADING
        A ready state constant for IE (state 2).
        See Also:
        Constant Field Values
      • READY_STATE_LOADED

        public static final java.lang.String READY_STATE_LOADED
        A ready state constant for IE (state 3).
        See Also:
        Constant Field Values
      • READY_STATE_INTERACTIVE

        public static final java.lang.String READY_STATE_INTERACTIVE
        A ready state constant for IE (state 4).
        See Also:
        Constant Field Values
      • READY_STATE_COMPLETE

        public static final java.lang.String READY_STATE_COMPLETE
        A ready state constant for IE (state 5).
        See Also:
        Constant Field Values
      • PROPERTY_ELEMENT

        public static final java.lang.String PROPERTY_ELEMENT
        The name of the "element" property. Used when watching property change events.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DomNode

        protected DomNode​(SgmlPage page)
        Creates a new instance.
        Parameters:
        page - the page which contains this node
    • Method Detail

      • setStartLocation

        public void setStartLocation​(int startLineNumber,
                                     int startColumnNumber)
        Sets the line and column numbers in the source page where the DOM node starts.
        Parameters:
        startLineNumber - the line number where the DOM node starts
        startColumnNumber - the column number where the DOM node starts
      • setEndLocation

        public void setEndLocation​(int endLineNumber,
                                   int endColumnNumber)
        Sets the line and column numbers in the source page where the DOM node ends.
        Parameters:
        endLineNumber - the line number where the DOM node ends
        endColumnNumber - the column number where the DOM node ends
      • getStartLineNumber

        public int getStartLineNumber()
        Returns the line number in the source page where the DOM node starts.
        Returns:
        the line number in the source page where the DOM node starts
      • getStartColumnNumber

        public int getStartColumnNumber()
        Returns the column number in the source page where the DOM node starts.
        Returns:
        the column number in the source page where the DOM node starts
      • getEndLineNumber

        public int getEndLineNumber()
        Returns the line number in the source page where the DOM node ends.
        Returns:
        0 if no information on the line number is available (for instance for nodes dynamically added), -1 if the end tag has not yet been parsed (during page loading)
      • getEndColumnNumber

        public int getEndColumnNumber()
        Returns the column number in the source page where the DOM node ends.
        Returns:
        0 if no information on the line number is available (for instance for nodes dynamically added), -1 if the end tag has not yet been parsed (during page loading)
      • getPage

        public SgmlPage getPage()
        Returns the page that contains this node.
        Returns:
        the page that contains this node
      • getHtmlPageOrNull

        public HtmlPage getHtmlPageOrNull()
        Returns the page that contains this node.
        Returns:
        the page that contains this node
      • getOwnerDocument

        public org.w3c.dom.Document getOwnerDocument()
        Specified by:
        getOwnerDocument in interface org.w3c.dom.Node
      • setScriptableObject

        public void setScriptableObject​(org.htmlunit.javascript.HtmlUnitScriptable scriptObject)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Sets the JavaScript object that corresponds to this node. This is not guaranteed to be set even if there is a JavaScript object for this DOM node.
        Parameters:
        scriptObject - the JavaScript object
      • getLastChild

        public DomNode getLastChild()
        Specified by:
        getLastChild in interface org.w3c.dom.Node
      • getParentNode

        public DomNode getParentNode()
        Specified by:
        getParentNode in interface org.w3c.dom.Node
      • setParentNode

        protected void setParentNode​(DomNode parent)
        Sets the parent node.
        Parameters:
        parent - the parent node
      • getIndex

        public int getIndex()
        Returns this node's index within its parent's child nodes (zero-based).
        Returns:
        this node's index within its parent's child nodes (zero-based)
      • getPreviousSibling

        public DomNode getPreviousSibling()
        Specified by:
        getPreviousSibling in interface org.w3c.dom.Node
      • getNextSibling

        public DomNode getNextSibling()
        Specified by:
        getNextSibling in interface org.w3c.dom.Node
      • getFirstChild

        public DomNode getFirstChild()
        Specified by:
        getFirstChild in interface org.w3c.dom.Node
      • isAncestorOf

        public boolean isAncestorOf​(DomNode node)
        Returns true if this node is an ancestor of the specified node.
        Parameters:
        node - the node to check
        Returns:
        true if this node is an ancestor of the specified node
      • isAncestorOfAny

        public boolean isAncestorOfAny​(DomNode... nodes)
        Returns true if this node is an ancestor of the specified nodes.
        Parameters:
        nodes - the nodes to check
        Returns:
        true if this node is an ancestor of the specified nodes
      • getNamespaceURI

        public java.lang.String getNamespaceURI()
        Specified by:
        getNamespaceURI in interface org.w3c.dom.Node
      • getLocalName

        public java.lang.String getLocalName()
        Specified by:
        getLocalName in interface org.w3c.dom.Node
      • getPrefix

        public java.lang.String getPrefix()
        Specified by:
        getPrefix in interface org.w3c.dom.Node
      • hasChildNodes

        public boolean hasChildNodes()
        Specified by:
        hasChildNodes in interface org.w3c.dom.Node
      • getChildNodes

        public DomNodeList<DomNode> getChildNodes()
        Specified by:
        getChildNodes in interface org.w3c.dom.Node
      • isSupported

        public boolean isSupported​(java.lang.String namespace,
                                   java.lang.String featureName)
        Not yet implemented.
        Specified by:
        isSupported in interface org.w3c.dom.Node
      • normalize

        public void normalize()
        Specified by:
        normalize in interface org.w3c.dom.Node
      • getBaseURI

        public java.lang.String getBaseURI()
        Specified by:
        getBaseURI in interface org.w3c.dom.Node
      • compareDocumentPosition

        public short compareDocumentPosition​(org.w3c.dom.Node other)
        Specified by:
        compareDocumentPosition in interface org.w3c.dom.Node
      • getAncestors

        public java.util.List<org.w3c.dom.Node> getAncestors()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Gets the ancestors of the node.
        Returns:
        a list of the ancestors with the root at the first position
      • getTextContent

        public java.lang.String getTextContent()
        Specified by:
        getTextContent in interface org.w3c.dom.Node
      • setTextContent

        public void setTextContent​(java.lang.String textContent)
        Specified by:
        setTextContent in interface org.w3c.dom.Node
      • isSameNode

        public boolean isSameNode​(org.w3c.dom.Node other)
        Specified by:
        isSameNode in interface org.w3c.dom.Node
      • lookupPrefix

        public java.lang.String lookupPrefix​(java.lang.String namespaceURI)
        Not yet implemented.
        Specified by:
        lookupPrefix in interface org.w3c.dom.Node
      • isDefaultNamespace

        public boolean isDefaultNamespace​(java.lang.String namespaceURI)
        Not yet implemented.
        Specified by:
        isDefaultNamespace in interface org.w3c.dom.Node
      • lookupNamespaceURI

        public java.lang.String lookupNamespaceURI​(java.lang.String prefix)
        Not yet implemented.
        Specified by:
        lookupNamespaceURI in interface org.w3c.dom.Node
      • isEqualNode

        public boolean isEqualNode​(org.w3c.dom.Node arg)
        Not yet implemented.
        Specified by:
        isEqualNode in interface org.w3c.dom.Node
      • getFeature

        public java.lang.Object getFeature​(java.lang.String feature,
                                           java.lang.String version)
        Not yet implemented.
        Specified by:
        getFeature in interface org.w3c.dom.Node
      • getUserData

        public java.lang.Object getUserData​(java.lang.String key)
        Specified by:
        getUserData in interface org.w3c.dom.Node
      • setUserData

        public java.lang.Object setUserData​(java.lang.String key,
                                            java.lang.Object data,
                                            org.w3c.dom.UserDataHandler handler)
        Specified by:
        setUserData in interface org.w3c.dom.Node
      • hasAttributes

        public boolean hasAttributes()
        Specified by:
        hasAttributes in interface org.w3c.dom.Node
      • getAttributes

        public org.w3c.dom.NamedNodeMap getAttributes()
        Specified by:
        getAttributes in interface org.w3c.dom.Node
      • isDisplayed

        public boolean isDisplayed()

        Returns true if this node is displayed and can be visible to the user (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).

        NOTE: If CSS is disabled, this method does not take this element's style into consideration!

        Returns:
        true if the node is visible to the user, false otherwise
        See Also:
        CSS2 Visibility, CSS2 Display, MSDN Documentation, mayBeDisplayed()
      • mayBeDisplayed

        public boolean mayBeDisplayed()
        Returns true if nodes of this type can ever be displayed, false otherwise. Examples of nodes that can never be displayed are <head>, <meta>, <script>, etc.
        Returns:
        true if nodes of this type can ever be displayed, false otherwise
        See Also:
        isDisplayed()
      • asNormalizedText

        public java.lang.String asNormalizedText()
        Returns a normalized textual representation of this element that represents what would be visible to the user if this page was shown in a web browser. Whitespace is normalized like in the browser and block tags are separated by '\n'.
        Returns:
        a normalized textual representation of this element
      • getVisibleText

        public java.lang.String getVisibleText()
        Returns a textual representation of this element in the same way as the selenium/WebDriver WebElement#getText() property does.
        see get-element-text and dfn-bot-dom-getvisibletext Note: this is different from asNormalizedText()
        Returns:
        a textual representation of this element that represents what would be visible to the user if this page was shown in a web browser
      • asXml

        public java.lang.String asXml()
        Returns a string representation of the XML document from this element and all it's children (recursively). The charset used is the current page encoding.
        Returns:
        the XML string
      • printXml

        protected void printXml​(java.lang.String indent,
                                java.io.PrintWriter printWriter)
        Recursively writes the XML data for the node tree starting at node.
        Parameters:
        indent - white space to indent child nodes
        printWriter - writer where child nodes are written
      • printChildrenAsXml

        protected void printChildrenAsXml​(java.lang.String indent,
                                          java.io.PrintWriter printWriter)
        Recursively writes the XML data for the node tree starting at node.
        Parameters:
        indent - white space to indent child nodes
        printWriter - writer where child nodes are written
      • getNodeValue

        public java.lang.String getNodeValue()
        Specified by:
        getNodeValue in interface org.w3c.dom.Node
      • cloneNode

        public DomNode cloneNode​(boolean deep)
        Specified by:
        cloneNode in interface org.w3c.dom.Node
      • getScriptableObject

        public <T extends org.htmlunit.javascript.HtmlUnitScriptable> T getScriptableObject()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

        Returns the JavaScript object that corresponds to this node, lazily initializing a new one if necessary.

        The logic of when and where the JavaScript object is created needs a clean up: functions using a DOM node's JavaScript object should not have to check if they should create it first.

        Type Parameters:
        T - the object type
        Returns:
        the JavaScript object that corresponds to this node
      • appendChild

        public DomNode appendChild​(org.w3c.dom.Node node)
        Specified by:
        appendChild in interface org.w3c.dom.Node
      • insertBefore

        public org.w3c.dom.Node insertBefore​(org.w3c.dom.Node newChild,
                                             org.w3c.dom.Node refChild)
        Specified by:
        insertBefore in interface org.w3c.dom.Node
      • insertBefore

        public void insertBefore​(DomNode newNode)
        Inserts the specified node as a new child node before this node into the child relationship this node is a part of. If the specified node is this node, this method is a no-op.
        Parameters:
        newNode - the new node to insert
      • removeChild

        public org.w3c.dom.Node removeChild​(org.w3c.dom.Node child)
        Specified by:
        removeChild in interface org.w3c.dom.Node
      • removeAllChildren

        public void removeAllChildren()
        Removes all of this node's children.
      • parseHtmlSnippet

        public void parseHtmlSnippet​(java.lang.String source)
                              throws org.xml.sax.SAXException,
                                     java.io.IOException
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parses the specified HTML source code, appending the resulting content at the specified target location.
        Parameters:
        source - the HTML code extract to parse
        Throws:
        java.io.IOException - in case of error
        org.xml.sax.SAXException - in case of error
      • remove

        public void remove()
        Removes this node from all relationships with other nodes.
      • detach

        protected void detach()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Detach this node from all relationships with other nodes. This is the first step of a move.
      • basicRemove

        protected void basicRemove()
        Cuts off all relationships this node has with siblings and parents.
      • replaceChild

        public org.w3c.dom.Node replaceChild​(org.w3c.dom.Node newChild,
                                             org.w3c.dom.Node oldChild)
        Specified by:
        replaceChild in interface org.w3c.dom.Node
      • replace

        public void replace​(DomNode newNode)
        Replaces this node with another node. If the specified node is this node, this method is a no-op.
        Parameters:
        newNode - the node to replace this one
      • quietlyRemoveAndMoveChildrenTo

        public void quietlyRemoveAndMoveChildrenTo​(DomNode destination)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Quietly removes this node and moves its children to the specified destination. "Quietly" means that no node events are fired. This method is not appropriate for most use cases. It should only be used in specific cases for HTML parsing hackery.
        Parameters:
        destination - the node to which this node's children should be moved before this node is removed
      • checkChildHierarchy

        protected void checkChildHierarchy​(org.w3c.dom.Node newChild)
                                    throws org.w3c.dom.DOMException
        Check for insertion errors for a new child node. This is overridden by derived classes to enforce which types of children are allowed.
        Parameters:
        newChild - the new child node that is being inserted below this node
        Throws:
        org.w3c.dom.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 insert 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 insert a second DocumentType or Element node. WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
      • onAddedToPage

        protected void onAddedToPage()
        Lifecycle method invoked whenever a node is added to a page. Intended to be overridden by nodes which need to perform custom logic when they are added to a page. This method is recursive, so if you override it, please be sure to call super.onAddedToPage().
      • onAllChildrenAddedToPage

        public void onAllChildrenAddedToPage​(boolean postponed)
        Lifecycle method invoked after a node and all its children have been added to a page, during parsing of the HTML. Intended to be overridden by nodes which need to perform custom logic after they and all their child nodes have been processed by the HTML parser. This method is not recursive, and the default implementation is empty, so there is no need to call super.onAllChildrenAddedToPage() if you implement this method.
        Parameters:
        postponed - whether to use PostponedAction or no
      • onAddedToDocumentFragment

        protected void onAddedToDocumentFragment()
        Lifecycle method invoked whenever a node is added to a document fragment. Intended to be overridden by nodes which need to perform custom logic when they are added to a fragment. This method is recursive, so if you override it, please be sure to call super.onAddedToDocumentFragment().
      • getChildren

        public final java.lang.Iterable<DomNode> getChildren()
        Returns:
        an Iterable over the children of this node
      • getDescendants

        public final java.lang.Iterable<DomNode> getDescendants()
        Returns an Iterable that will recursively iterate over all of this node's descendants, including DomText elements, DomComment elements, etc. If you want to iterate only over HtmlElement descendants, please use getHtmlElementDescendants().
        Returns:
        an Iterable that will recursively iterate over all of this node's descendants
      • getHtmlElementDescendants

        public final java.lang.Iterable<HtmlElement> getHtmlElementDescendants()
        Returns an Iterable that will recursively iterate over all of this node's HtmlElement descendants. If you want to iterate over all descendants (including DomText elements, DomComment elements, etc.), please use getDescendants().
        Returns:
        an Iterable that will recursively iterate over all of this node's HtmlElement descendants
        See Also:
        getDomElementDescendants()
      • getDomElementDescendants

        public final java.lang.Iterable<DomElement> getDomElementDescendants()
        Returns an Iterable that will recursively iterate over all of this node's DomElement descendants. If you want to iterate over all descendants (including DomText elements, DomComment elements, etc.), please use getDescendants().
        Returns:
        an Iterable that will recursively iterate over all of this node's DomElement descendants
        See Also:
        getHtmlElementDescendants()
      • getReadyState

        public java.lang.String getReadyState()
        Returns this node's ready state (IE only).
        Returns:
        this node's ready state
      • setReadyState

        public void setReadyState​(java.lang.String state)
        Sets this node's ready state (IE only).
        Parameters:
        state - this node's ready state
      • getByXPath

        public <T> java.util.List<T> getByXPath​(java.lang.String xpathExpr)
        Evaluates the specified XPath expression from this node, returning the matching elements.
        Note: This implies that the ',' point to this node but the general axis like '//' are still looking at the whole document. E.g. if you like to get all child h1 nodes from the current one you have to use './/h1' instead of '//h1' because the latter matches all h1 nodes of the# whole document.
        Type Parameters:
        T - the expected type
        Parameters:
        xpathExpr - the XPath expression to evaluate
        Returns:
        the elements which match the specified XPath expression
        See Also:
        getFirstByXPath(String), getCanonicalXPath()
      • getByXPath

        public java.util.List<?> getByXPath​(java.lang.String xpathExpr,
                                            org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
        Evaluates the specified XPath expression from this node, returning the matching elements.
        Parameters:
        xpathExpr - the XPath expression to evaluate
        resolver - the prefix resolver to use for resolving namespace prefixes, or null
        Returns:
        the elements which match the specified XPath expression
        See Also:
        getFirstByXPath(String), getCanonicalXPath()
      • getFirstByXPath

        public <X> X getFirstByXPath​(java.lang.String xpathExpr)
        Evaluates the specified XPath expression from this node, returning the first matching element, or null if no node matches the specified XPath expression.
        Type Parameters:
        X - the expression type
        Parameters:
        xpathExpr - the XPath expression
        Returns:
        the first element matching the specified XPath expression
        See Also:
        getByXPath(String), getCanonicalXPath()
      • getFirstByXPath

        public <X> X getFirstByXPath​(java.lang.String xpathExpr,
                                     org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
        Evaluates the specified XPath expression from this node, returning the first matching element, or null if no node matches the specified XPath expression.
        Type Parameters:
        X - the expression type
        Parameters:
        xpathExpr - the XPath expression
        resolver - the prefix resolver to use for resolving namespace prefixes, or null
        Returns:
        the first element matching the specified XPath expression
        See Also:
        getByXPath(String), getCanonicalXPath()
      • getCanonicalXPath

        public java.lang.String getCanonicalXPath()

        Returns the canonical XPath expression which identifies this node, for instance "/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]".

        WARNING: This sort of automated XPath expression is often quite bad at identifying a node, as it is highly sensitive to changes in the DOM tree.

        Returns:
        the canonical XPath expression which identifies this node
        See Also:
        getByXPath(String)
      • notifyIncorrectness

        protected void notifyIncorrectness​(java.lang.String message)
        Notifies the registered IncorrectnessListener of something that is not fully correct.
        Parameters:
        message - the notification to send to the registered IncorrectnessListener
      • fireNodeAdded

        protected void fireNodeAdded​(DomChangeEvent event)
        Support for reporting DOM changes. This method can be called when a node has been added, and it will send the appropriate DomChangeEvent to any registered DomChangeListeners.

        Note that this method recursively calls this node's parent's fireNodeAdded(DomChangeEvent).

        Parameters:
        event - the DomChangeEvent to be propagated
      • fireNodeDeleted

        protected void fireNodeDeleted​(DomChangeEvent event)
        Support for reporting DOM changes. This method can be called when a node has been deleted, and it will send the appropriate DomChangeEvent to any registered DomChangeListeners.

        Note that this method recursively calls this node's parent's fireNodeDeleted(DomChangeEvent).

        Parameters:
        event - the DomChangeEvent to be propagated
      • querySelectorAll

        public DomNodeList<DomNode> querySelectorAll​(java.lang.String selectors)
        Retrieves all element nodes from descendants of the starting element node that match any selector within the supplied selector strings.
        Parameters:
        selectors - one or more CSS selectors separated by commas
        Returns:
        list of all found nodes
      • getSelectorList

        protected org.htmlunit.cssparser.parser.selector.SelectorList getSelectorList​(java.lang.String selectors,
                                                                                      WebClient webClient)
                                                                               throws java.io.IOException
        Returns the SelectorList.
        Parameters:
        selectors - the selectors
        webClient - the WebClient
        Returns:
        the SelectorList
        Throws:
        java.io.IOException - if an error occurs
      • querySelector

        public <N extends DomNode> N querySelector​(java.lang.String selectors)
        Returns the first element within the document that matches the specified group of selectors.
        Type Parameters:
        N - the node type
        Parameters:
        selectors - one or more CSS selectors separated by commas
        Returns:
        null if no matches are found; otherwise, it returns the first matching element
      • isAttachedToPage

        public boolean isAttachedToPage()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Indicates if this node is currently attached to the page.
        Returns:
        true if the page is one ancestor of the node.
      • processImportNode

        public void processImportNode​(org.htmlunit.javascript.host.dom.Document doc)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Lifecycle method to support special processing for js method importNode.
        Parameters:
        doc - the import target document
        See Also:
        Document.importNode( org.htmlunit.javascript.host.dom.Node, boolean), HtmlScript.processImportNode(org.htmlunit.javascript.host.dom.Document)
      • hasFeature

        public boolean hasFeature​(BrowserVersionFeatures feature)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Helper for a common call sequence.
        Parameters:
        feature - the feature to check
        Returns:
        true if the currently emulated browser has this feature.
      • handles

        public boolean handles​(org.htmlunit.javascript.host.event.Event event)
        Indicates if the provided event can be applied to this node. Overwrite this.
        Parameters:
        event - the event
        Returns:
        false if the event can't be applied
      • getPreviousElementSibling

        public DomElement getPreviousElementSibling()
        Returns the previous sibling element node of this element. null if this element has no element sibling nodes that come before this one in the document tree.
        Returns:
        the previous sibling element node of this element. null if this element has no element sibling nodes that come before this one in the document tree
      • getNextElementSibling

        public DomElement getNextElementSibling()
        Returns the next sibling element node of this element. null if this element has no element sibling nodes that come after this one in the document tree.
        Returns:
        the next sibling element node of this element. null if this element has no element sibling nodes that come after this one in the document tree
      • closest

        public DomElement closest​(java.lang.String selectorString)
        Parameters:
        selectorString - the selector to test
        Returns:
        the selected DomElement or null.