evaluate()
方法在
XPathEvaluator
interface executes an XPath expression on the given node or document and returns an
XPathResult
.
XPathResult XPathEvaluator.evaluate(expression, contextNode, resolver, type, result);
DOMString
representing the XPath expression to be parsed and evaluated.
节点
representing the context to use for evaluating the expression.
xml
namespace prefix, within the XPath expression into appropriate namespace URIs.
XPathResult.Constants
.
null
or the implementation does not reuse the specified result, a new result object will be returned.
XPathResult
object representing the result of evaluating the XPath expression.
If the expression is not legal according to the rules of the
XPathEvaluator
,
XPathException
类型
INVALID_EXPRESSION_ERR
被引发。
In case result cannot be converted to the specified type, an
XPathException
类型
TYPE_ERR
被引发。
If the expression contains namespace prefixes which cannot be resolved by the specified
XPathNSResolver
,
DOMException
类型
NAMESPACE_ERROR
被引发。
If the provided context node is from a document that is not supported by the
XPathEvaluator
,
DOMException
类型
WRONG_DOCUMENT_ERR
被引发。
If the provided context node is not a type permitted as an XPath context node or the request type is not permitted by the
XPathEvaluator
,
DOMException
类型
NOT_SUPPORTED_ERR
被引发。
The following example shows the use of the
evaluate()
方法。
<div>XPath example</div> <div>Number of <div>s: <output></output></div>
var evaluator = new XPathEvaluator();
var result = evaluator.evaluate("//div", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
document.querySelector("output").textContent = result.snapshotLength;
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM (文档对象模型) 3 级 XPath 规范
The definition of 'XPathEvaluator.evaluate()' in that specification. |
推荐 | 初始定义 |
No compatibility data found. Please contribute data for "api.XPathEvaluator.evaluate()" (depth: 1) to the MDN 兼容性数据存储库 .
XPathEvaluator
createExpression()
createNSResolver()
evaluate()