public abstract class DomNode extends Object implements Cloneable, Serializable, Node
Modifier and Type | Class and Description |
---|---|
protected static class |
DomNode.ChildIterator
An iterator over all children of this node.
|
protected class |
DomNode.DescendantElementsIterator<T extends DomNode>
Iterates over all descendants of a specific type, in document order.
|
Modifier and Type | Field and Description |
---|---|
static String |
PROPERTY_ELEMENT
The name of the "element" property.
|
static String |
READY_STATE_COMPLETE
A ready state constant (state 5).
|
static String |
READY_STATE_INTERACTIVE
A ready state constant (state 4).
|
static String |
READY_STATE_LOADED
A ready state constant (state 3).
|
static String |
READY_STATE_LOADING
A ready state constant (state 2).
|
static String |
READY_STATE_UNINITIALIZED
A ready state constant (state 1).
|
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
Modifier | Constructor and Description |
---|---|
protected |
DomNode(SgmlPage page)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addCharacterDataChangeListener(CharacterDataChangeListener listener)
Adds a
CharacterDataChangeListener to the listener list. |
void |
addDomChangeListener(DomChangeListener listener)
Adds a
DomChangeListener to the listener list. |
DomNode |
appendChild(Node node) |
String |
asNormalizedText()
Returns a normalized textual representation of this element that represents
what would be visible to the user if this page was shown in a web browser.
|
String |
asXml()
Returns a string representation as XML document from this element and all it's children (recursively).
|
protected void |
basicRemove()
Cuts off all relationships this node has with siblings and parents.
|
protected void |
checkChildHierarchy(Node newChild)
Check for insertion errors for a new child node.
|
DomNode |
cloneNode(boolean deep) |
DomElement |
closest(String selectorString) |
short |
compareDocumentPosition(Node other) |
protected void |
detach()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
protected void |
fireCharacterDataChanged(DomCharacterData characterData,
String oldValue)
Support for reporting Character Data changes.
|
protected void |
fireNodeAdded(DomNode parentNode,
DomNode addedNode)
Support for reporting DOM changes.
|
protected void |
fireNodeDeleted(DomNode parentNode,
DomNode deletedNode)
Support for reporting DOM changes.
|
List<Node> |
getAncestors()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
NamedNodeMap |
getAttributes() |
String |
getBaseURI() |
<T> List<T> |
getByXPath(String xpathExpr)
Evaluates the specified XPath expression from this node, returning the matching elements.
|
List<?> |
getByXPath(String xpathExpr,
org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
Evaluates the specified XPath expression from this node, returning the matching elements.
|
String |
getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance
"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]" . |
DomNodeList<DomNode> |
getChildNodes() |
Iterable<DomNode> |
getChildren() |
Iterable<DomNode> |
getDescendants()
Returns an
Iterable that will recursively iterate over all of this node's descendants,
including DomText elements, DomComment elements, etc. |
Iterable<DomElement> |
getDomElementDescendants()
Returns an
Iterable that will recursively iterate over all of this node's DomElement
descendants. |
int |
getEndColumnNumber()
Returns the column number in the source page where the DOM node ends.
|
int |
getEndLineNumber()
Returns the line number in the source page where the DOM node ends.
|
Object |
getFeature(String feature,
String version)
Not yet implemented.
|
<X> X |
getFirstByXPath(String xpathExpr)
Evaluates the specified XPath expression from this node, returning the first matching element,
or
null if no node matches the specified XPath expression. |
<X> X |
getFirstByXPath(String xpathExpr,
org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
Evaluates the specified XPath expression from this node, returning the first matching element,
or
null if no node matches the specified XPath expression. |
DomNode |
getFirstChild() |
Iterable<HtmlElement> |
getHtmlElementDescendants()
Returns an
Iterable that will recursively iterate over all of this node's HtmlElement
descendants. |
HtmlPage |
getHtmlPageOrNull()
Returns the page that contains this node.
|
int |
getIndex()
Returns this node's index within its parent's child nodes (zero-based).
|
DomNode |
getLastChild() |
String |
getLocalName() |
String |
getNamespaceURI() |
DomElement |
getNextElementSibling()
Returns the next sibling element node of this element.
|
DomNode |
getNextSibling() |
String |
getNodeValue() |
Document |
getOwnerDocument() |
SgmlPage |
getPage()
Returns the page that contains this node.
|
DomNode |
getParentNode() |
String |
getPrefix() |
DomElement |
getPreviousElementSibling()
Returns the previous sibling element node of this element.
|
DomNode |
getPreviousSibling() |
String |
getReadyState()
Returns this node's ready state (IE only).
|
<T extends HtmlUnitScriptable> |
getScriptableObject()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
protected org.htmlunit.cssparser.parser.selector.SelectorList |
getSelectorList(String selectors,
WebClient webClient)
Returns the
SelectorList . |
int |
getStartColumnNumber()
Returns the column number in the source page where the DOM node starts.
|
int |
getStartLineNumber()
Returns the line number in the source page where the DOM node starts.
|
String |
getTextContent() |
Object |
getUserData(String key) |
String |
getVisibleText()
Returns a textual representation of this element in the same way as
the selenium/WebDriver WebElement#getText() property does.
|
boolean |
handles(Event event)
Indicates if the provided event can be applied to this node.
|
boolean |
hasAttributes() |
boolean |
hasChildNodes() |
boolean |
hasFeature(BrowserVersionFeatures feature)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
insertBefore(DomNode newNode)
Inserts the specified node as a new child node before this node into the child relationship this node is a
part of.
|
Node |
insertBefore(Node newChild,
Node refChild) |
boolean |
isAncestorOf(DomNode node)
Returns
true if this node is an ancestor of the specified node. |
boolean |
isAncestorOfAny(DomNode... nodes)
Returns
true if this node is an ancestor of the specified nodes. |
boolean |
isAttachedToPage()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
boolean |
isDefaultNamespace(String namespaceURI)
Not yet implemented.
|
boolean |
isDisplayed()
Returns
true if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes). |
boolean |
isEqualNode(Node arg)
Not yet implemented.
|
boolean |
isSameNode(Node other) |
boolean |
isSupported(String namespace,
String featureName)
Not yet implemented.
|
String |
lookupNamespaceURI(String prefix)
Not yet implemented.
|
String |
lookupPrefix(String namespaceURI)
Not yet implemented.
|
boolean |
mayBeDisplayed()
Returns
true if nodes of this type can ever be displayed, false otherwise. |
void |
normalize() |
protected void |
notifyIncorrectness(String message)
Notifies the registered
IncorrectnessListener of something that is not fully correct. |
protected void |
onAddedToDocumentFragment()
Lifecycle method invoked whenever a node is added to a document fragment.
|
protected void |
onAddedToPage()
Lifecycle method invoked whenever a node is added to a page.
|
void |
onAllChildrenAddedToPage(boolean postponed)
Lifecycle method invoked after a node and all its children have been added to a page, during
parsing of the HTML.
|
void |
parseHtmlSnippet(String source)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
protected void |
printChildrenAsXml(String indent,
PrintWriter printWriter)
Recursively writes the XML data for the node tree starting at
node . |
protected void |
printXml(String indent,
PrintWriter printWriter)
Recursively writes the XML data for the node tree starting at
node . |
void |
processImportNode(Document doc)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
<N extends DomNode> |
querySelector(String selectors)
Returns the first element within the document that matches the specified group of selectors.
|
DomNodeList<DomNode> |
querySelectorAll(String selectors)
Retrieves all element nodes from descendants of the starting element node that match any selector
within the supplied selector strings.
|
void |
quietlyRemoveAndMoveChildrenTo(DomNode destination)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
remove()
Removes this node from all relationships with other nodes.
|
void |
removeAllChildren()
Removes all of this node's children.
|
void |
removeCharacterDataChangeListener(CharacterDataChangeListener listener)
Removes a
CharacterDataChangeListener from the listener list. |
Node |
removeChild(Node child) |
void |
removeDomChangeListener(DomChangeListener listener)
Removes a
DomChangeListener from the listener list. |
void |
replace(DomNode newNode)
Replaces this node with another node.
|
Node |
replaceChild(Node newChild,
Node oldChild) |
void |
setEndLocation(int endLineNumber,
int endColumnNumber)
Sets the line and column numbers in the source page where the DOM node ends.
|
protected void |
setParentNode(DomNode parent)
Sets the parent node.
|
void |
setReadyState(String state)
Sets this node's ready state (IE only).
|
void |
setScriptableObject(HtmlUnitScriptable scriptObject)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
setStartLocation(int startLineNumber,
int startColumnNumber)
Sets the line and column numbers in the source page where the DOM node starts.
|
void |
setTextContent(String textContent) |
Object |
setUserData(String key,
Object data,
UserDataHandler handler) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getNodeName, getNodeType, setNodeValue, setPrefix
public static final String READY_STATE_UNINITIALIZED
public static final String READY_STATE_LOADING
public static final String READY_STATE_LOADED
public static final String READY_STATE_INTERACTIVE
public static final String READY_STATE_COMPLETE
public static final String PROPERTY_ELEMENT
protected DomNode(SgmlPage page)
page
- the page which contains this nodepublic void setStartLocation(int startLineNumber, int startColumnNumber)
startLineNumber
- the line number where the DOM node startsstartColumnNumber
- the column number where the DOM node startspublic void setEndLocation(int endLineNumber, int endColumnNumber)
endLineNumber
- the line number where the DOM node endsendColumnNumber
- the column number where the DOM node endspublic int getStartLineNumber()
public int getStartColumnNumber()
public int getEndLineNumber()
public int getEndColumnNumber()
public SgmlPage getPage()
public HtmlPage getHtmlPageOrNull()
public Document getOwnerDocument()
getOwnerDocument
in interface Node
public void setScriptableObject(HtmlUnitScriptable scriptObject)
scriptObject
- the JavaScript objectpublic DomNode getLastChild()
getLastChild
in interface Node
public DomNode getParentNode()
getParentNode
in interface Node
protected void setParentNode(DomNode parent)
parent
- the parent nodepublic int getIndex()
public DomNode getPreviousSibling()
getPreviousSibling
in interface Node
public DomNode getNextSibling()
getNextSibling
in interface Node
public DomNode getFirstChild()
getFirstChild
in interface Node
public boolean isAncestorOf(DomNode node)
true
if this node is an ancestor of the specified node.node
- the node to checktrue
if this node is an ancestor of the specified nodepublic boolean isAncestorOfAny(DomNode... nodes)
true
if this node is an ancestor of the specified nodes.nodes
- the nodes to checktrue
if this node is an ancestor of the specified nodespublic String getNamespaceURI()
getNamespaceURI
in interface Node
public String getLocalName()
getLocalName
in interface Node
public boolean hasChildNodes()
hasChildNodes
in interface Node
public DomNodeList<DomNode> getChildNodes()
getChildNodes
in interface Node
public boolean isSupported(String namespace, String featureName)
isSupported
in interface Node
public String getBaseURI()
getBaseURI
in interface Node
public short compareDocumentPosition(Node other)
compareDocumentPosition
in interface Node
public List<Node> getAncestors()
public String getTextContent()
getTextContent
in interface Node
public void setTextContent(String textContent)
setTextContent
in interface Node
public boolean isSameNode(Node other)
isSameNode
in interface Node
public String lookupPrefix(String namespaceURI)
lookupPrefix
in interface Node
public boolean isDefaultNamespace(String namespaceURI)
isDefaultNamespace
in interface Node
public String lookupNamespaceURI(String prefix)
lookupNamespaceURI
in interface Node
public boolean isEqualNode(Node arg)
isEqualNode
in interface Node
public Object getFeature(String feature, String version)
getFeature
in interface Node
public Object getUserData(String key)
getUserData
in interface Node
public Object setUserData(String key, Object data, UserDataHandler handler)
setUserData
in interface Node
public boolean hasAttributes()
hasAttributes
in interface Node
public NamedNodeMap getAttributes()
getAttributes
in interface Node
public boolean isDisplayed()
Returns true
if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).
NOTE: If CSS is
disabled
, this method
does not take this element's style into consideration!
true
if the node is visible to the user, false
otherwisemayBeDisplayed()
public boolean mayBeDisplayed()
true
if nodes of this type can ever be displayed, false
otherwise. Examples of nodes
that can never be displayed are <head>
,
<meta>
, <script>
, etc.true
if nodes of this type can ever be displayed, false
otherwiseisDisplayed()
public String asNormalizedText()
public String getVisibleText()
asNormalizedText()
public String asXml()
protected void printXml(String indent, PrintWriter printWriter)
node
.indent
- white space to indent child nodesprintWriter
- writer where child nodes are writtenprotected void printChildrenAsXml(String indent, PrintWriter printWriter)
node
.indent
- white space to indent child nodesprintWriter
- writer where child nodes are writtenpublic String getNodeValue()
getNodeValue
in interface Node
public <T extends HtmlUnitScriptable> T getScriptableObject()
Returns the JavaScript object that corresponds to this node, lazily initializing a new one if necessary.
The logic of when and where the JavaScript object is created needs a clean up: functions using a DOM node's JavaScript object should not have to check if they should create it first.
T
- the object typepublic DomNode appendChild(Node node)
appendChild
in interface Node
public Node insertBefore(Node newChild, Node refChild)
insertBefore
in interface Node
public void insertBefore(DomNode newNode)
newNode
- the new node to insertpublic Node removeChild(Node child)
removeChild
in interface Node
public void removeAllChildren()
public void parseHtmlSnippet(String source) throws SAXException, IOException
source
- the HTML code extract to parseIOException
- in case of errorSAXException
- in case of errorpublic void remove()
protected void detach()
protected void basicRemove()
public Node replaceChild(Node newChild, Node oldChild)
replaceChild
in interface Node
public void replace(DomNode newNode)
newNode
- the node to replace this onepublic void quietlyRemoveAndMoveChildrenTo(DomNode destination)
destination
- the node to which this node's children should be moved before this node is removedprotected void checkChildHierarchy(Node newChild) throws DOMException
newChild
- the new child node that is being inserted below this nodeDOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does
not allow children of the type of the newChild node, or if the node to insert is one of
this node's ancestors or this node itself, or if this node is of type Document and the
DOM application attempts to insert a second DocumentType or Element node.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the
one that created this node.protected void onAddedToPage()
super.onAddedToPage()
.public void onAllChildrenAddedToPage(boolean postponed)
super.onAllChildrenAddedToPage()
if you implement this method.postponed
- whether to use PostponedAction
or noprotected void onAddedToDocumentFragment()
super.onAddedToDocumentFragment()
.public final Iterable<DomNode> getChildren()
Iterable
over the children of this nodepublic final Iterable<DomNode> getDescendants()
Iterable
that will recursively iterate over all of this node's descendants,
including DomText
elements, DomComment
elements, etc. If you want to iterate
only over HtmlElement
descendants, please use getHtmlElementDescendants()
.Iterable
that will recursively iterate over all of this node's descendantspublic final Iterable<HtmlElement> getHtmlElementDescendants()
Iterable
that will recursively iterate over all of this node's HtmlElement
descendants. If you want to iterate over all descendants (including DomText
elements,
DomComment
elements, etc.), please use getDescendants()
.Iterable
that will recursively iterate over all of this node's HtmlElement
descendantsgetDomElementDescendants()
public final Iterable<DomElement> getDomElementDescendants()
Iterable
that will recursively iterate over all of this node's DomElement
descendants. If you want to iterate over all descendants (including DomText
elements,
DomComment
elements, etc.), please use getDescendants()
.Iterable
that will recursively iterate over all of this node's DomElement
descendantsgetHtmlElementDescendants()
public String getReadyState()
public void setReadyState(String state)
state
- this node's ready statepublic <T> List<T> getByXPath(String xpathExpr)
T
- the expected typexpathExpr
- the XPath expression to evaluategetFirstByXPath(String)
,
getCanonicalXPath()
public List<?> getByXPath(String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
xpathExpr
- the XPath expression to evaluateresolver
- the prefix resolver to use for resolving namespace prefixes, or nullgetFirstByXPath(String)
,
getCanonicalXPath()
public <X> X getFirstByXPath(String xpathExpr)
null
if no node matches the specified XPath expression.X
- the expression typexpathExpr
- the XPath expressiongetByXPath(String)
,
getCanonicalXPath()
public <X> X getFirstByXPath(String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
null
if no node matches the specified XPath expression.X
- the expression typexpathExpr
- the XPath expressionresolver
- the prefix resolver to use for resolving namespace prefixes, or nullgetByXPath(String)
,
getCanonicalXPath()
public String getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance
"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]"
.
WARNING: This sort of automated XPath expression is often quite bad at identifying a node, as it is highly sensitive to changes in the DOM tree.
getByXPath(String)
protected void notifyIncorrectness(String message)
IncorrectnessListener
of something that is not fully correct.message
- the notification to send to the registered IncorrectnessListener
public void addDomChangeListener(DomChangeListener listener)
DomChangeListener
to the listener list. The listener is registered for
all descendants of this node.listener
- the DOM structure change listener to be addedremoveDomChangeListener(DomChangeListener)
public void removeDomChangeListener(DomChangeListener listener)
DomChangeListener
from the listener list. The listener is deregistered for
all descendants of this node.listener
- the DOM structure change listener to be removedaddDomChangeListener(DomChangeListener)
protected void fireNodeAdded(DomNode parentNode, DomNode addedNode)
DomChangeEvent
to any registered DomChangeListener
s.
Note that this method recursively calls this node's parent's fireNodeAdded(DomNode, DomNode)
.
parentNode
- the parent of the node that was changedaddedNode
- the node that has been addedpublic void addCharacterDataChangeListener(CharacterDataChangeListener listener)
CharacterDataChangeListener
to the listener list. The listener is registered for
all descendants of this node.listener
- the character data change listener to be addedremoveCharacterDataChangeListener(CharacterDataChangeListener)
public void removeCharacterDataChangeListener(CharacterDataChangeListener listener)
CharacterDataChangeListener
from the listener list. The listener is deregistered for
all descendants of this node.listener
- the Character Data change listener to be removedaddCharacterDataChangeListener(CharacterDataChangeListener)
protected void fireCharacterDataChanged(DomCharacterData characterData, String oldValue)
Note that this method recursively calls this node's parent's fireCharacterDataChanged(org.htmlunit.html.DomCharacterData, java.lang.String)
.
characterData
- the character data which is changedoldValue
- the old valueprotected void fireNodeDeleted(DomNode parentNode, DomNode deletedNode)
DomChangeEvent
to any registered DomChangeListener
s.
Note that this method recursively calls this node's parent's fireNodeDeleted(DomNode, DomNode)
.
parentNode
- the parent of the node that was changeddeletedNode
- the node that has been deletedpublic DomNodeList<DomNode> querySelectorAll(String selectors)
selectors
- one or more CSS selectors separated by commasprotected org.htmlunit.cssparser.parser.selector.SelectorList getSelectorList(String selectors, WebClient webClient) throws IOException
SelectorList
.selectors
- the selectorswebClient
- the WebClient
SelectorList
IOException
- if an error occurspublic <N extends DomNode> N querySelector(String selectors)
N
- the node typeselectors
- one or more CSS selectors separated by commaspublic boolean isAttachedToPage()
true
if the page is one ancestor of the node.public void processImportNode(Document doc)
doc
- the import target documentDocument.importNode(
org.htmlunit.javascript.host.dom.Node, boolean)
,
HtmlScript.processImportNode(org.htmlunit.javascript.host.dom.Document)
public boolean hasFeature(BrowserVersionFeatures feature)
feature
- the feature to checktrue
if the currently emulated browser has this feature.public boolean handles(Event event)
event
- the eventfalse
if the event can't be appliedpublic DomElement getPreviousElementSibling()
public DomElement getNextElementSibling()
public DomElement closest(String selectorString)
selectorString
- the selector to testDomElement
or null.Copyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.