Package com.pd4ml.dom

Class Node

  • Direct Known Subclasses:
    Comment, Document, DocumentType, Element, Text

    public abstract class Node
    extends java.lang.Object
    A node of the document PD4ML.getDocument() returns: an Element, a Text, a Comment or the Document itself. The methods follow the browser DOM: changes made before the document is written (writePDF() etc.) are laid out as if the HTML had been written that way.

    Node objects are views: two objects for the same node are equal.

    Since:
    v4.2.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Node appendChild​(Node child)
      Appends a node as the last child.
      Node cloneNode​(boolean deep)
      A copy of this node, not in the tree, belonging to the same document (a copied document is a document of its own).
      boolean contains​(Node other)
      True if the node is this node or one of its descendants.
      boolean equals​(java.lang.Object o)  
      java.util.List<Node> getChildNodes()
      The children, in document order (a snapshot: later changes do not show in it).
      Node getFirstChild()  
      Node getLastChild()  
      Node getNextSibling()  
      java.lang.String getNodeName()
      The node name: the tag name of an element (lower case), #text, #comment, #document or #doctype.
      Document getOwnerDocument()
      The document this node belongs to (for a document, the document itself).
      Element getParentElement()
      The parent if it is an element, otherwise null.
      Node getParentNode()
      The parent node, or null for a document or a node that is not in a tree.
      Node getPreviousSibling()  
      java.lang.String getTextContent()
      The concatenated text of this node and its descendants (no comments).
      boolean hasChildNodes()  
      int hashCode()  
      Node insertBefore​(Node child, Node ref)
      Inserts a node before a child of this node (ref null: at the end).
      void remove()
      Removes this node from its parent (nothing happens if it has none).
      Node removeChild​(Node child)
      Removes a child of this node.
      Node replaceChild​(Node replacement, Node old)
      Replaces a child of this node.
      void setTextContent​(java.lang.String text)
      Replaces the content of this node with the text: an element's children are replaced by one text node (none for an empty text); a text or comment gets the text as its data.
      java.lang.String toHtml()
      The HTML of this node (for a document, the whole document).
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getNodeName

        public java.lang.String getNodeName()
        The node name: the tag name of an element (lower case), #text, #comment, #document or #doctype.
      • getParentNode

        public Node getParentNode()
        The parent node, or null for a document or a node that is not in a tree.
      • getParentElement

        public Element getParentElement()
        The parent if it is an element, otherwise null.
      • getOwnerDocument

        public Document getOwnerDocument()
        The document this node belongs to (for a document, the document itself).
      • getChildNodes

        public java.util.List<Node> getChildNodes()
        The children, in document order (a snapshot: later changes do not show in it).
      • hasChildNodes

        public boolean hasChildNodes()
      • getFirstChild

        public Node getFirstChild()
      • getLastChild

        public Node getLastChild()
      • getNextSibling

        public Node getNextSibling()
      • getPreviousSibling

        public Node getPreviousSibling()
      • getTextContent

        public java.lang.String getTextContent()
        The concatenated text of this node and its descendants (no comments).
      • setTextContent

        public void setTextContent​(java.lang.String text)
        Replaces the content of this node with the text: an element's children are replaced by one text node (none for an empty text); a text or comment gets the text as its data.
      • appendChild

        public Node appendChild​(Node child)
        Appends a node as the last child. A node already in a tree is moved; a node of another document is moved into this one.
        Returns:
        the appended node
        Throws:
        java.lang.IllegalArgumentException - if the node is this node, one of its ancestors or a document
      • insertBefore

        public Node insertBefore​(Node child,
                                 Node ref)
        Inserts a node before a child of this node (ref null: at the end).
        Returns:
        the inserted node
        Throws:
        java.lang.IllegalArgumentException - if ref is not a child of this node, or as appendChild(com.pd4ml.dom.Node)
      • replaceChild

        public Node replaceChild​(Node replacement,
                                 Node old)
        Replaces a child of this node.
        Returns:
        the replaced (now detached) node
        Throws:
        java.lang.IllegalArgumentException - if old is not a child of this node, or as appendChild(com.pd4ml.dom.Node)
      • removeChild

        public Node removeChild​(Node child)
        Removes a child of this node.
        Returns:
        the removed node
        Throws:
        java.lang.IllegalArgumentException - if it is not a child of this node
      • remove

        public void remove()
        Removes this node from its parent (nothing happens if it has none).
      • cloneNode

        public Node cloneNode​(boolean deep)
        A copy of this node, not in the tree, belonging to the same document (a copied document is a document of its own).
        Parameters:
        deep - copy the descendants too
      • contains

        public boolean contains​(Node other)
        True if the node is this node or one of its descendants.
      • toHtml

        public java.lang.String toHtml()
        The HTML of this node (for a document, the whole document).
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object