public interface Node extends EventTarget, SearchContext
Modifier and Type | Method and Description |
---|---|
boolean |
appendChild(Node childNode)
Adds the given
node as a child of the current node to the end of its children list. |
java.util.List<Node> |
children()
Returns an immutable list of all children of this node.
|
void |
click()
Simulates a click on the node.
|
java.util.Set<DocumentPosition> |
compareDocumentPosition(Node otherNode)
Compares position of the current node against another node in a DOM tree.
|
Document |
document()
Returns the
Document instance of this node. |
XPathResult |
evaluate(java.lang.String expression)
Evaluates the given XPath
expression for the node and returns the XPathResult
of the XPathResultType.ANY type. |
XPathResult |
evaluate(java.lang.String expression,
XPathResultType type)
Evaluates the given XPath
expression for the node and returns the XPathResult
object of the given type . |
boolean |
insertChild(Node node,
Node beforeNode)
Inserts the given
node before the given beforeNode as a child of the current
node. |
java.util.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 . |
java.lang.String |
nodeName()
Returns a string that represents the node name in the UTF8 format.
|
java.lang.String |
nodeValue()
Returns a string that represents the node value.
|
void |
nodeValue(java.lang.String value)
Updates the node value with the given new
value . |
java.util.Optional<Node> |
parent()
Returns an
Optional that contains the parent of this node. |
java.util.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 . |
boolean |
removeChild(Node childNode)
Removes the given
childNode of the current node from the DOM. |
boolean |
replaceChild(Node newNode,
Node oldNode)
Replaces the given child
oldNode of the current node with the given newNode . |
java.lang.String |
textContent()
Returns the text content of the current node and its descendants.
|
void |
textContent(java.lang.String textContent)
Removes all the current node children and replaces them with a single text node with the
given
textContent . |
NodeType |
type()
Returns the node type.
|
java.lang.String |
xPath()
Returns a string that represents XPath to the current Node or an empty string if it is not
available.
|
addEventListener, dispatch, eventListeners, removeEventListener
findElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagName
Document document()
Document
instance of this node.java.lang.String nodeName()
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" | |
NodeType#ENTITY_REFERENCE_NODE |
The name of entity reference | |
NodeType#ENTITY_NODE |
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" | |
NodeType#NOTATION_NODE |
The notation name |
java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.lang.String nodeValue()
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#ENTITY_REFERENCE_NODE |
null | |
NodeType#ENTITY_NODE |
null | |
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 | |
NodeType#NOTATION_NODE |
null |
java.lang.IllegalStateException
- when the document this instance belongs to is closedvoid nodeValue(java.lang.String value)
value
.
This method does nothing, if it is invoked for the node of one of the following types:
NodeType.ELEMENT_NODE
, NodeType#ENTITY_REFERENCE_NODE
, NodeType#ENTITY_NODE
, NodeType.DOCUMENT_NODE
, NodeType.DOCUMENT_TYPE_NODE
,
NodeType.DOCUMENT_FRAGMENT_NODE
, NodeType#NOTATION_NODE
.
value
- a new node valuejava.lang.IllegalStateException
- when the document this instance belongs to is closednodeValue()
NodeType type()
java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.Optional<Node> parent()
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
.java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.List<Node> children()
Please note, that this method should be invoked every time in case of need to retrieve an actual children list.
java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.Optional<Node> nextSibling()
Optional
that contains the next node in the document tree if such a node
exists, otherwise returns an empty Optional
.java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.Optional<Node> previousSibling()
Optional
that contains the previous node in the document tree if such a
node exists, otherwise returns an empty Optional
.java.lang.IllegalStateException
- when the document this instance belongs to is closedvoid click()
java.lang.IllegalStateException
- when the document this instance belongs to is closedboolean insertChild(Node node, Node beforeNode)
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.node
- the node to insertbeforeNode
- the node before which the node
will be insertedtrue
if the given node
was successfully insertedjava.lang.IllegalStateException
- when the document this instance belongs to is closedboolean replaceChild(Node newNode, Node oldNode)
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.newNode
- the new node to replace the oldNode
oldNode
- the existing node to be replacedtrue
if the given oldNode
was successfully replacedjava.lang.IllegalStateException
- when the document this instance belongs to is closedboolean removeChild(Node childNode)
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.childNode
- the existing node to be removedtrue
if the given node
was successfully removedjava.lang.IllegalStateException
- when the document this instance belongs to is closedboolean appendChild(Node childNode)
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.childNode
- the node to appendtrue
if the given node
was successfully insertedjava.lang.IllegalStateException
- when the document this instance belongs to is closedjava.lang.String textContent()
NodeType.DOCUMENT_NODE
, NodeType.DOCUMENT_TYPE_NODE
, or NodeType#NOTATION_NODE
.
NodeType.C_DATA_SECTION_NODE
, NodeType.COMMENT_NODE
, NodeType.PROCESSING_INSTRUCTIONS_NODE
, or NodeType.TEXT_NODE
.
java.lang.IllegalStateException
- when the document this instance belongs to is closedvoid textContent(java.lang.String textContent)
textContent
.textContent
- the new text content of the current nodejava.lang.IllegalStateException
- when the document this instance belongs to is closedXPathResult evaluate(java.lang.String expression)
expression
for the node and returns the XPathResult
of the XPathResultType.ANY
type.expression
- a string representing the XPath to be evaluatedjava.lang.IllegalArgumentException
- when expression
is emptyXPathException
- when this method failed to evaluate the given expression
java.lang.IllegalStateException
- when the document this instance belongs to is closedevaluate(String, XPathResultType)
XPathResult evaluate(java.lang.String expression, XPathResultType type)
expression
for the node and returns the XPathResult
object of the given type
.expression
- a string representing the XPath to be evaluatedtype
- type of XPathResult
to returnjava.lang.IllegalArgumentException
- when expression
is empty or blankXPathException
- when this method failed to evaluate the given expression
and
return a result of the given type
java.lang.IllegalStateException
- when the document this instance belongs to is closedXPathResultType
java.lang.String xPath()
For the document()
this method returns an empty string.
java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.Set<DocumentPosition> compareDocumentPosition(Node otherNode)
otherNode
- the node to be compared to the current nodeotherNode
parameter
relates to the position of the current nodejava.lang.IllegalStateException
- when the document this instance belongs to is closed