Package com.pd4ml.dom
Class Node
- java.lang.Object
-
- com.pd4ml.dom.Node
-
- Direct Known Subclasses:
Comment,Document,DocumentType,Element,Text
public abstract class Node extends java.lang.ObjectA node of the documentPD4ML.getDocument()returns: anElement, aText, aCommentor theDocumentitself. 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 NodeappendChild(Node child)Appends a node as the last child.NodecloneNode(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).booleancontains(Node other)True if the node is this node or one of its descendants.booleanequals(java.lang.Object o)java.util.List<Node>getChildNodes()The children, in document order (a snapshot: later changes do not show in it).NodegetFirstChild()NodegetLastChild()NodegetNextSibling()java.lang.StringgetNodeName()The node name: the tag name of an element (lower case),#text,#comment,#documentor#doctype.DocumentgetOwnerDocument()The document this node belongs to (for a document, the document itself).ElementgetParentElement()The parent if it is an element, otherwise null.NodegetParentNode()The parent node, or null for a document or a node that is not in a tree.NodegetPreviousSibling()java.lang.StringgetTextContent()The concatenated text of this node and its descendants (no comments).booleanhasChildNodes()inthashCode()NodeinsertBefore(Node child, Node ref)Inserts a node before a child of this node (refnull: at the end).voidremove()Removes this node from its parent (nothing happens if it has none).NoderemoveChild(Node child)Removes a child of this node.NodereplaceChild(Node replacement, Node old)Replaces a child of this node.voidsetTextContent(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.StringtoHtml()The HTML of this node (for a document, the whole document).java.lang.StringtoString()
-
-
-
Method Detail
-
getNodeName
public java.lang.String getNodeName()
The node name: the tag name of an element (lower case),#text,#comment,#documentor#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 (refnull: at the end).- Returns:
- the inserted node
- Throws:
java.lang.IllegalArgumentException- ifrefis not a child of this node, or asappendChild(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- ifoldis not a child of this node, or asappendChild(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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-