diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/xpathevaluator | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/xpathevaluator')
-rw-r--r-- | files/zh-cn/web/api/xpathevaluator/index.html | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/xpathevaluator/index.html b/files/zh-cn/web/api/xpathevaluator/index.html new file mode 100644 index 0000000000..7ce04064f3 --- /dev/null +++ b/files/zh-cn/web/api/xpathevaluator/index.html @@ -0,0 +1,88 @@ +--- +title: XPathEvaluator +slug: Web/API/XPathEvaluator +tags: + - API + - DOM + - DOM XPath API + - Document + - Interface + - NeedsTranslation + - Reference + - TopicStub + - XML + - XPath + - XPathEvaluator +translation_of: Web/API/XPathEvaluator +--- +<p>{{APIRef("DOM XPath")}}</p> + +<p> <code>XPathEvaluator</code> 接口能够对 {{Glossary("XPath")}} 表达式进行编译和求值。</p> + +<p>该接口实现自{{domxref("Document")}}的接口。</p> + +<h2 id="Methods" name="Methods">方法</h2> + +<dl> + <dt>{{DOMxRef("XPathEvaluator.createExpression()")}}</dt> + <dd>创建一个解析过的XPath和解析后的namespaces</dd> + <dt>{{DOMxRef("XPathEvaluator.createNSResolver()")}}</dt> + <dd>任意DOM节点能够通过该方法来解析namespaces,允许通过节点出现在文档中的相对上下文对XPath表达式进行求值。</dd> + <dt>{{DOMxRef("XPathEvaluator.evaluate()")}}</dt> + <dd>对XPath字符串求值,返回可能的确切类型的匹配结果。</dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>下面的实例展示了如何使用<code>XPathEvaluator</code>接口。</p> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><div>XPath example</div> +<div>Number of &lt;div&gt;s: <output></output></div> +</pre> + +<h3 id="JavaScript">JavaScript</h3> + +<pre class="brush: js">var xpath = "//div"; +var evaluator = new XPathEvaluator(); +var expression = evaluator.createExpression("//div"); +var result = expression.evaluate(document, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); +document.querySelector("output").textContent = result.snapshotLength; +</pre> + +<h3 id="结果"> 结果</h3> + + + +<p>{{EmbedLiveSample('Example', 400, 70)}}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName("DOM3 XPath", "xpath.html#XPathEvaluator", "XPathEvaluator")}}</td> + <td>{{Spec2("DOM3 XPath")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.XPathEvaluator")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{domxref("document.createExpression()")}}</li> + <li>{{domxref("XPathExpression")}}</li> +</ul> |