Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. XPathResult

XPathResult

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheXPathResult 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.

Instance properties

XPathResult.booleanValueRead only

Aboolean representing the value of the result ifresultType isBOOLEAN_TYPE.

XPathResult.invalidIteratorStateRead only

Signifies that the iterator has become invalid. It istrue ifresultType isUNORDERED_NODE_ITERATOR_TYPE orORDERED_NODE_ITERATOR_TYPE and the document has been modified since this result was returned.

XPathResult.numberValueRead only

Anumber representing the value of the result ifresultType isNUMBER_TYPE.

XPathResult.resultTypeRead only

Anumber code representing the type of the result, as defined by the type constants.

XPathResult.singleNodeValueRead only

ANode representing 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 string representing the value of the result ifresultType isSTRING_TYPE.

Instance methods

XPathResult.iterateNext()

If the result is a node set, this method iterates over it and returns the next node from it ornull if there are no more nodes.

XPathResult.snapshotItem()

Returns an item of the snapshot collection ornull 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.

Constants

Result Type Defined ConstantValueDescription
ANY_TYPE0 A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set thenUNORDERED_NODE_ITERATOR_TYPE is always the resulting type.
NUMBER_TYPE1 A result containing a single number. This is useful for example, in an XPath expression using thecount() function.
STRING_TYPE2A result containing a single string.
BOOLEAN_TYPE3 A result containing a single boolean value. This is useful for example, in an XPath expression using thenot() function.
UNORDERED_NODE_ITERATOR_TYPE4 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_TYPE5 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_TYPE6 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_TYPE7 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_TYPE8 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_TYPE9 A result node-set containing the first node in the document that matches the expression.

Specifications

Specification
DOM
# interface-xpathresult

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp