XPathResult
The XPathResult interface represents the results generated by evaluating an XPath expression within the context of a given node.
Since XPath expressions can result in a variety of result types, this interface makes it possible to determine and handle the type and value of the result.
Properties
-
XPathResult.booleanValueRead only -
A
booleanrepresenting the value of the result ifresultTypeisBOOLEAN_TYPE. -
XPathResult.invalidIteratorStateRead only -
Signifies that the iterator has become invalid. It is
trueifresultTypeisUNORDERED_NODE_ITERATOR_TYPEorORDERED_NODE_ITERATOR_TYPEand the document has been modified since this result was returned. -
XPathResult.numberValueRead only -
A
numberrepresenting the value of the result ifresultTypeisNUMBER_TYPE. -
XPathResult.resultTypeRead only -
A
numbercode representing the type of the result, as defined by the type constants. -
XPathResult.singleNodeValueRead only -
A
Noderepresenting the value of the single node result, which may benull. -
XPathResult.snapshotLengthRead only -
The number of nodes in the result snapshot.
-
XPathResult.stringValueRead only -
A
stringrepresenting the value of the result ifresultTypeisSTRING_TYPE.
Methods
XPathResult.iterateNext()-
If the result is a node set, this method iterates over it and returns the next node from it or
nullif there are no more nodes. XPathResult.snapshotItem()-
Returns an item of the snapshot collection or
nullin case the index is not within the range of nodes. Unlike the iterator result, the snapshot does not become invalid, but may not correspond to the current document if it is mutated.
Constants
| Result Type Defined Constant | Value | Description |
|---|---|---|
ANY_TYPE | 0 | A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type. |
NUMBER_TYPE | 1 | A result containing a single number. This is useful for example, in an XPath expression using the count() function. |
STRING_TYPE | 2 | A result containing a single string. |
BOOLEAN_TYPE | 3 | A result containing a single boolean value. This is useful for example, in an XPath expression using the not() function. |
UNORDERED_NODE_ITERATOR_TYPE | 4 | A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. |
ORDERED_NODE_ITERATOR_TYPE | 5 | A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. |
UNORDERED_NODE_SNAPSHOT_TYPE | 6 | A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. |
ORDERED_NODE_SNAPSHOT_TYPE | 7 | A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. |
ANY_UNORDERED_NODE_TYPE | 8 | A result node-set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression. |
FIRST_ORDERED_NODE_TYPE | 9 | A result node-set containing the first node in the document that matches the expression. |
Specifications
| Specification |
|---|
| DOM Standard (DOM) # interface-xpathresult |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
XPathResult |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
booleanValue |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
invalidIteratorState |
1 |
12 |
1 |
No |
15 |
3 |
≤37 |
18 |
4 |
14 |
1 |
1.0 |
iterateNext |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
numberValue |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
resultType |
1 |
12 |
1 |
No |
15 |
3 |
≤37 |
18 |
4 |
14 |
1 |
1.0 |
singleNodeValue |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
snapshotItem |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
snapshotLength |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
stringValue |
1 |
12 |
1 |
No |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XPathResult