Interface Node
- All Superinterfaces:
EventTarget
,SearchContext
- All Known Subinterfaces:
Attribute
,Document
,Element
,FormControlElement
,FormElement
,FrameElement
,ImageElement
,InputElement
,OptionElement
,SelectElement
,TextAreaElement
-
Method Summary
Modifier and TypeMethodDescriptionboolean
appendChild
(Node childNode) Adds the givennode
as a child of the current node to the end of its children list.children()
Returns an immutable list of all children of this node.void
click()
Simulates a click on the node.void
close()
Closes this node.compareDocumentPosition
(Node otherNode) Compares position of the current node against another node in a DOM tree.document()
Returns theDocument
instance of this node.Evaluates the given XPathexpression
for the node and returns theXPathResult
of theXPathResultType.ANY
type.evaluate
(String expression, XPathResultType type) Evaluates the given XPathexpression
for the node and returns theXPathResult
object of the giventype
.boolean
insertChild
(Node node, Node beforeNode) Inserts the givennode
before the givenbeforeNode
as a child of the current node.Returns anOptional
that contains the next node in the document tree if such a node exists, otherwise returns an emptyOptional
.nodeName()
Returns a string that represents the node name in the UTF8 format.Returns a string that represents the node value.void
Updates the node value with the given newvalue
.parent()
Returns anOptional
that contains the parent of this node.Returns anOptional
that contains the previous node in the document tree if such a node exists, otherwise returns an emptyOptional
.boolean
removeChild
(Node childNode) Removes the givenchildNode
of the current node from the DOM.boolean
replaceChild
(Node newNode, Node oldNode) Replaces the given childoldNode
of the current node with the givennewNode
.Returns the text content of the current node and its descendants.void
textContent
(String textContent) Removes all the current node children and replaces them with a single text node with the giventextContent
.type()
Returns the node type.xPath()
Returns a string that represents XPath to the current Node or an empty string if it is not available.Methods inherited from interface com.teamdev.jxbrowser.dom.event.EventTarget
addEventListener, dispatch, eventListeners, removeEventListener
Methods inherited from interface com.teamdev.jxbrowser.dom.SearchContext
findElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagName
-
Method Details
-
document
Document document()Returns theDocument
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
attributeNodeType.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
Updates the node value with the given newvalue
.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
Returns anOptional
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 emptyOptional
.- Throws:
ObjectClosedException
- when this node is closed
-
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
Returns anOptional
that contains the next node in the document tree if such a node exists, otherwise returns an emptyOptional
.- Throws:
ObjectClosedException
- when this node is closed
-
previousSibling
Returns anOptional
that contains the previous node in the document tree if such a node exists, otherwise returns an emptyOptional
.- Throws:
ObjectClosedException
- when this node is closed
-
click
void click()Simulates a click on the node.- Throws:
ObjectClosedException
- when this node is closed
-
insertChild
Inserts the givennode
before the givenbeforeNode
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 thenode
is existing node, it will be moved to a new location in the document.- Parameters:
node
- the node to insertbeforeNode
- the node before which thenode
will be inserted- Returns:
true
if the givennode
was successfully inserted- Throws:
ObjectClosedException
- when this node is closed
-
replaceChild
Replaces the given childoldNode
of the current node with the givennewNode
. The new node can be an existing node in the document, or you can create and insert a new node. If thenewNode
is existing node, it will be moved to a new location in the document.- Parameters:
newNode
- the new node to replace theoldNode
oldNode
- the existing node to be replaced- Returns:
true
if the givenoldNode
was successfully replaced- Throws:
ObjectClosedException
- when this node is closed
-
removeChild
Removes the givenchildNode
of the current node from the DOM. The removedchildNode
still exists, but is no longer part of the DOM. You can reuse the removed node later in your code via thechildNode
object reference.- Parameters:
childNode
- the existing node to be removed- Returns:
true
if the givennode
was successfully removed- Throws:
ObjectClosedException
- when this node is closed
-
appendChild
Adds the givennode
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 thenode
is existing node, it will be moved to a new location in the document.- Parameters:
childNode
- the node to append- Returns:
true
if the givennode
was successfully inserted- Throws:
ObjectClosedException
- when this node is closed
-
textContent
String textContent()Returns the text content of the current node and its descendants.- Returns an empty string if the node is one of the following types:
NodeType.DOCUMENT_NODE
orNodeType.DOCUMENT_TYPE_NODE
. -
Returns the node value if the node is a
NodeType.C_DATA_SECTION_NODE
,NodeType.COMMENT_NODE
,NodeType.PROCESSING_INSTRUCTIONS_NODE
, orNodeType.TEXT_NODE
. - For other node types returns the concatenated text content of every child node, excluding comments and processing instructions. Returns an empty string if the current node has no children.
- Throws:
ObjectClosedException
- when this node is closed
- Returns an empty string if the node is one of the following types:
-
textContent
Removes all the current node children and replaces them with a single text node with the giventextContent
.- Parameters:
textContent
- the new text content of the current node- Throws:
ObjectClosedException
- when this node is closed
-
evaluate
Evaluates the given XPathexpression
for the node and returns theXPathResult
of theXPathResultType.ANY
type.- Parameters:
expression
- a string representing the XPath to be evaluated- Throws:
IllegalArgumentException
- whenexpression
is emptyXPathException
- when this method failed to evaluate the givenexpression
ObjectClosedException
- when this node is closed- See Also:
-
evaluate
Evaluates the given XPathexpression
for the node and returns theXPathResult
object of the giventype
.- Parameters:
expression
- a string representing the XPath to be evaluatedtype
- type ofXPathResult
to return- Throws:
IllegalArgumentException
- whenexpression
is empty or blankXPathException
- when this method failed to evaluate the givenexpression
and return a result of the giventype
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
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
-