大网数据广告活动
Web 标准与前端开发

XPathResult

· 52CE 我爱测

The **`XPathResult`** interface represents the results generated by evaluating an XPath expression within the context of a given node.

DOM

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.

Constants

<table class="no-markdown"> <thead> <tr> <th>Result Type Defined Constant</th> <th>Value</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>ANY_TYPE</code></td> <td><code>0</code></td> <td> A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then <code>UNORDERED_NODE_ITERATOR_TYPE</code> is always the resulting type. </td> </tr> <tr> <td><code>NUMBER_TYPE</code></td> <td><code>1</code></td> <td> A result containing a single number. This is useful for example, in an XPath expression using the <code>count()</code> function. </td> </tr> <tr> <td><code>STRING_TYPE</code></td> <td><code>2</code></td> <td>A result containing a single string.</td> </tr> <tr> <td><code>BOOLEAN_TYPE</code></td> <td><code>3</code></td> <td> A result containing a single boolean value. This is useful for example, in an XPath expression using the <code>not()</code> function. </td> </tr> <tr> <td><code>UNORDERED_NODE_ITERATOR_TYPE</code></td> <td><code>4</code></td> <td> 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. </td> </tr> <tr> <td><code>ORDERED_NODE_ITERATOR_TYPE</code></td> <td><code>5</code></td> <td> 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. </td> </tr> <tr> <td><code>UNORDERED_NODE_SNAPSHOT_TYPE</code></td> <td><code>6</code></td> <td> 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. </td> </tr> <tr> <td><code>ORDERED_NODE_SNAPSHOT_TYPE</code></td> <td><code>7</code></td> <td> 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. </td> </tr> <tr> <td><code>ANY_UNORDERED_NODE_TYPE</code></td> <td><code>8</code></td> <td> 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. </td> </tr> <tr> <td><code>FIRST_ORDERED_NODE_TYPE</code></td> <td><code>9</code></td> <td> A result node-set containing the first node in the document that matches the expression. </td> </tr> </tbody> </table>

Instance properties

  • XPathResult.booleanValue
    • : A boolean representing the value of the result if resultType is BOOLEAN_TYPE.
  • XPathResult.invalidIteratorState
    • : Signifies that the iterator has become invalid. It is 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
    • : A number representing the value of the result if resultType is NUMBER_TYPE.
  • XPathResult.resultType
    • : A number code representing the type of the result, as defined by the type constants.
  • XPathResult.singleNodeValue
    • : A Node representing the value of the single node result, which may be null.
  • XPathResult.snapshotLength
    • : The number of nodes in the result snapshot.
  • XPathResult.stringValue
    • : A string representing the value of the result if resultType is STRING_TYPE.

Instance methods

  • XPathResult.iterateNext()
    • : If the result is a node set, this method iterates over it and returns the next node from it or null if there are no more nodes.
  • XPathResult.snapshotItem()
    • : Returns an item of the snapshot collection or 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.

Specifications

Browser compatibility

See also

  • Document.evaluate()
  • XPathExpression

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。