1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
---
title: XPath
slug: Web/XPath
tags:
- XPath
translation_of: Web/XPath
---
<p><span class="seoSummary">XPath 的意思是 XML 路径语言。它使用的一个非 XML 语法提供一种灵活地定位 <a href="/zh-CN/docs/XML" title="XML">XML</a> 文档的不同部分的方法。它同时也可以用于检测文档中某个节点是否与某个模式(pattern)匹配。</span></p>
<p>XPath 主要被用于 <a href="/zh-CN/docs/XSLT" title="XSLT">XSLT</a>,也可用于定位文档元素,像类 XML 语言文档(如HTML 和 <a href="/zh-CN/docs/XUL" title="XUL">XUL</a> ) 通过 <a href="/zh-CN/docs/DOM" title="DOM">DOM</a> 定位元素一样。替代 {{Domxref("document.getElementById")}} 方法、 {{Domxref("element.childNodes")}} 属性和其他DOM核心特性。</p>
<p>XPath 使用路径标识符通过层级结构来导航XML文档。它使用非XML语法,以致于它可以被用在URIs和XML属性值上。</p>
<div class="note">
<p><strong>注意:</strong>XPath 的浏览器支持差别很大;Firefox 支持地相当不错 (尽管没有计划进一步提高支持),而其他浏览器则较小程度地实现了它。如果你需要一个兼容主流浏览器的 XPath,你可以考虑试试 <a href="http://nchc.dl.sourceforge.net/project/js-xpath/js-xpath/1.0.0/xpath.js">js-xpath</a> 或 <a href="https://github.com/google/wicked-good-xpath">wicked-good-xpath</a>.</p>
</div>
<h2 class="Documentation" id="Documentation" name="Documentation">文档</h2>
<dl>
<dt><a href="/zh-CN/docs/Introduction_to_using_XPath_in_JavaScript" title="Introduction_to_using_XPath_in_JavaScript">在 JavaScript 中使用 XPath 的介绍</a></dt>
<dd>描述了 XPath 的一个非 XSLT 使用。</dd>
<dt><a href="/en-US/docs/XPath/Axes" title="XPath/Axes">XPath:Axes</a></dt>
<dd>List and definition of the axes defined in the XPath specification. Axes are used to describe the relationships between nodes.</dd>
<dt><a href="/en-US/docs/XPath/Functions" title="XPath/Functions">XPath:Functions</a></dt>
<dd>List and description of the core XPath functions and XSLT-specific additions to XPath.</dd>
<dt><a href="/en-US/docs/Transforming_XML_with_XSLT" title="Transforming_XML_with_XSLT">Transforming XML with XSLT</a></dt>
<dd>XSLT uses XPath to address code segments in a XML document that it wishes to transform.</dd>
<dt><a href="/en-US/docs/Web/XPath/Snippets" title="Using_XPath">XPath snippets</a></dt>
<dd>JavaScript utility functions to use in your own code, based on <a class="external external-icon" href="http://www.w3.org/TR/DOM-Level-3-XPath/">DOM Level 3 XPath </a>APIs.</dd>
<dt><a class="external" href="http://www.xml.com/pub/a/2000/08/holman/">What is XSLT?</a></dt>
<dd>This extensive introduction to XSLT and XPath assumes no prior knowledge of the technologies, and guides the reader through background, context, structure, concepts and introductory terminology.</dd>
<dt><a href="/en-US/docs/JXON" title="/en-US/docs/JXON">JXON</a></dt>
<dd><strong>JXON</strong> (lossless <strong>J</strong>avaScript <strong>X</strong>ML <strong>O</strong>bject <strong>N</strong>otation) is a generic name by which is defined the representation of JavaScript Objects using <a href="/en/XML" title="en/XML">XML</a>. There are some cases in which the whole content of an XML document must be read from the JavaScript interpreter (like for web-apps languages or settings XML documents, for example). In these cases JXON could represent the most practical way and a valid alternative to XPath.</dd>
</dl>
<h2 class="Tools" id="Tools" name="Tools">工具</h2>
<dl>
<dt><a class="link-https" href="https://addons.mozilla.org/zh-CN/firefox/addon/1192">XPather</a></dt>
<dd>Feature rich XPath generator, editor, inspector, and simple extraction tool (FireFox Add-On).</dd>
<dt><a class="link-https" href="https://addons.mozilla.org/zh-CN/firefox/addon/11900">FireXPath</a></dt>
<dd>XPath panel that integrates tightly into FireBug, providing an editor and inspector (FireFox Add-On).</dd>
<dt><a class="external" href="http://qutoric.com/xmlquire/">XMLQuire (formerly known as SketchPath)</a></dt>
<dd>A Graphical XPath Builder/Debugger(.NET).</dd>
</dl>
<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">相关主题</h2>
<ul>
<li><a href="/zh-CN/docs/XSLT" title="XSLT">XSLT</a>, <a href="/zh-CN/docs/XQuery" title="XQuery">XQuery</a>, <a href="/zh-CN/docs/XML" title="XML">XML</a>, <a href="/zh-CN/docs/DOM" title="DOM">DOM</a>, <a href="/zh-CN/docs/JXON" title="/zh-CN/docs/JXON">JXON</a>, <a href="/zh-CN/docs/JSON/JSONPath" title="JSON/JSONPath">JSONPath</a></li>
</ul>
<div>{{QuickLinksWithSubpages("/zh-CN/docs/Web/XPath")}}</div>
|