Interface Node
- All Superinterfaces:
EventTarget,SearchContext
- All Known Subinterfaces:
Attribute,Document,Element,FormControlElement,FormElement,FrameElement,ImageElement,InputElement,OptionElement,SelectElement,TextAreaElement
-
Method Summary
Modifier and TypeMethodDescriptionbooleanappendChild(Node childNode) Adds the givennodeas a child of the current node to the end of its children list.children()Returns an immutable list of all children of this node.voidclick()Simulates a click on the node.voidclose()Closes this node.compareDocumentPosition(Node otherNode) Compares position of the current node against another node in a DOM tree.document()Returns theDocumentinstance of this node.Evaluates the given XPathexpressionfor the node and returns theXPathResultof theXPathResultType.ANYtype.evaluate(String expression, XPathResultType type) Evaluates the given XPathexpressionfor the node and returns theXPathResultobject of the giventype.booleaninsertChild(Node node, Node beforeNode) Inserts the givennodebefore the givenbeforeNodeas a child of the current node.Returns anOptionalthat 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.voidUpdates the node value with the given newvalue.parent()Returns anOptionalthat contains the parent of this node.Returns anOptionalthat contains the previous node in the document tree if such a node exists, otherwise returns an emptyOptional.booleanremoveChild(Node childNode) Removes the givenchildNodeof the current node from the DOM.booleanreplaceChild(Node newNode, Node oldNode) Replaces the given childoldNodeof the current node with the givennewNode.Returns the text content of the current node and its descendants.voidtextContent(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, removeEventListenerMethods inherited from interface com.teamdev.jxbrowser.dom.SearchContext
findElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagName
-
Method Details
-
document
Document document()Returns theDocumentinstance 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_NODEThe 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_NODEThe attribute name NodeType.TEXT_NODE"#text" NodeType.C_DATA_SECTION_NODE"#cdata-section" The entity name NodeType.PROCESSING_INSTRUCTIONS_NODEThe value of the targetattributeNodeType.COMMENT_NODE"#comment" NodeType.DOCUMENT_NODE"#document" NodeType.DOCUMENT_TYPE_NODEThe 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_NODEnull NodeType.ATTRIBUTE_NODEThe attribute value NodeType.TEXT_NODEThe content of the text node NodeType.C_DATA_SECTION_NODEThe content of the CDATA Section NodeType.PROCESSING_INSTRUCTIONS_NODEThe entire node content excluding the target NodeType.COMMENT_NODEThe content of the comment NodeType.DOCUMENT_NODEnull NodeType.DOCUMENT_TYPE_NODEnull NodeType.DOCUMENT_FRAGMENT_NODEnull - 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 anOptionalthat 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 anOptionalthat 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 anOptionalthat 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 givennodebefore the givenbeforeNodeas 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 thenodeis existing node, it will be moved to a new location in the document.- Parameters:
node- the node to insertbeforeNode- the node before which thenodewill be inserted- Returns:
trueif the givennodewas successfully inserted- Throws:
ObjectClosedException- when this node is closed
-
replaceChild
Replaces the given childoldNodeof 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 thenewNodeis existing node, it will be moved to a new location in the document.- Parameters:
newNode- the new node to replace theoldNodeoldNode- the existing node to be replaced- Returns:
trueif the givenoldNodewas successfully replaced- Throws:
ObjectClosedException- when this node is closed
-
removeChild
Removes the givenchildNodeof the current node from the DOM. The removedchildNodestill exists, but is no longer part of the DOM. You can reuse the removed node later in your code via thechildNodeobject reference.- Parameters:
childNode- the existing node to be removed- Returns:
trueif the givennodewas successfully removed- Throws:
ObjectClosedException- when this node is closed
-
appendChild
Adds the givennodeas 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 thenodeis existing node, it will be moved to a new location in the document.- Parameters:
childNode- the node to append- Returns:
trueif the givennodewas 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_NODEorNodeType.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 XPathexpressionfor the node and returns theXPathResultof theXPathResultType.ANYtype.- Parameters:
expression- a string representing the XPath to be evaluated- Throws:
IllegalArgumentException- whenexpressionis emptyXPathException- when this method failed to evaluate the givenexpressionObjectClosedException- when this node is closed- See Also:
-
evaluate
Evaluates the given XPathexpressionfor the node and returns theXPathResultobject of the giventype.- Parameters:
expression- a string representing the XPath to be evaluatedtype- type ofXPathResultto return- Throws:
IllegalArgumentException- whenexpressionis empty or blankXPathException- when this method failed to evaluate the givenexpressionand return a result of the giventypeObjectClosedException- 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
otherNodeparameter 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
-