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.
XPathResult.booleanValue
只读
boolean
representing the value of the result if
resultType
is
BOOLEAN_TYPE
.
XPathResult.invalidIteratorState
只读
true
if
resultType
is
UNORDERED_NODE_ITERATOR_TYPE
or
ORDERED_NODE_ITERATOR_TYPE
and the document has been modified since this result was returned.
XPathResult.numberValue
只读
编号
representing the value of the result if
resultType
is
NUMBER_TYPE
.
XPathResult.resultType
只读
编号
code representing the type of the result, as defined by the type constants.
XPathResult.singleNodeValue
只读
节点
representing the value of the single node result, which may be
null
.
XPathResult.snapshotLength
只读
The number of nodes in the result snapshot.
XPathResult.stringValue
只读
string
representing the value of the result if
resultType
is
STRING_TYPE
.
XPathResult.iterateNext()
null
if there are no more nodes.
XPathResult.snapshotItem()
null
in 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.
| Result Type Defined Constant | 值 | 描述 |
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()
函数。
|
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()
函数。
|
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. |
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM (文档对象模型) 3 级 XPath 规范
The definition of 'XPathResult' in that specification. |
推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
XPathResult
|
Chrome Yes | Edge ≤18 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
invalidIteratorState
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
iterateNext
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
resultType
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
snapshotItem
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
完整支持
兼容性未知