- 浏览: 186551 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
iblike:
给我发一份,谢谢哦,iblike@163.com
Java实现的IP地址查询 - 性能不逊色于C -
编程的石头:
还可以再优化,你把地址库作一个分段,如1.1.1.1~63.1 ...
Java实现的IP地址查询 - 性能不逊色于C -
上官车月:
哥们 头像逆天啊
java Map排序(按key和按value) -
hwhwl:
给我也发一下吧 hwhwl@jpw.cn 我也需要这个
Java实现的IP地址查询 - 性能不逊色于C -
Longerandlonger:
return (o2.getValue() - o1.getV ...
java Map排序(按key和按value)
XPath
is a language for finding information in an XML document. XPath is used to
navigate through elements and attributes in an XML document.
Xpath
是一种能够在 XML
文档中寻找信息的语言。它通过 XML
文档中的元素和属性来进行导航。
What You Should Already Know
你应具备的知识
Before
you continue you should have a basic understanding of the following:
在你继续前你应该具备以下知识的基础:
· HTML / XHTML
· XML / XML Namespaces[ 命名空间 ]
What is XPath?
什么是 XPath?
·
XPath is a syntax for defining parts of an XML
document
XPath
是针对 XML
文档部分内容定义的语法
·
XPath uses path expressions to navigate in XML
documents
XPath
使用路径表达式在 XML
文档中导航
·
XPath contains a library of standard functions
XPath
包含了一系列标准函数
·
XPath is a major element in XSLT
XPath
在 XSLT
当中是一个主要的元素
·
XPath is a W3C Standard
XPath
是 W3C
标准
XPath Path Expressions
XPath
路径表达式
XPath
uses path expressions to select nodes or node-sets in an XML document. These
path expressions look very much like the expressions you see when you work with
a traditional computer file system.
XPath
使用路径表达式来选择 XML
文档中的 nodes(
节 )
或是
node-set(
节集 )
。这些路径表达式看上去与你平时所见的传统计算机文件系统路径非常地相似。
XPath Standard Functions
XPath
标准函数
XPath
includes over 100 built-in functions. There are functions for string values,
numeric values, date and time comparison, node and QName manipulation, sequence
manipulation, Boolean values, and more.
XPath
包含了数量超过 100
的内置函数。这些函数针对字符串值,数字值,日期和时间比较,节操作,顺序操作,布尔值,等等。
XPath is Used in XSLT
XPath
被用在 XSLT
XPath
is a major element in the XSLT standard. Without XPath knowledge you will not
be able to create XSLT documents.
在 XSLT
标准中
XPath
是主要的元素。没有 XPath
知识你将很难建立 XSLT
文档。
XQuery
and XPointer are both built on XPath expressions. XQuery 1.0 and XPath 2.0
share the same data model and support the same functions and operators.
XQuery
和 XPointer
都建立于 XPath
表达式。 XQuery 1.0
和 XPath 2.0
共享相同的数据模型并支持相同的函数和操作
XPath is a W3C Standard
XPath
是 W3C
标准
XPath
became a W3C Recommendation 16. November 1999.
XPat
于 1999
年
11
月 16
日 成为 W3C
的推荐标准
XPath
was designed to be used by XSLT, XPointer and other XML parsing software.
XPath
被设计成为用语 XSLT,XPoniter
以及其他 XML
解析的软件。
XPath
Nodes(
节 )
翻译: Linyupark / 2006-03-24
In
XPath, there are seven kinds of nodes: element, attribute, text, namespace,
processing-instruction, comment, and document (root) nodes.
在 XPath
中有七种
nodes(
节 )
:元素,属性,文字,命名空间,处理说明,注释,和文档
(
根 )
节。
XPath Terminology
XPath
术语
Nodes/ 节
In
XPath, there are seven kinds of nodes: element, attribute, text, namespace,
processing-instruction, comment, and document (root) nodes. XML documents are
treated as trees of nodes. The root of the tree is called the document node (or
root node).
XML
文档被视为数状的节。树的根部被称为文档的节 (
或根节 )
。
Look
at the following XML document:
观察下面的 XML
文档:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Example
of nodes in the XML document above:
上面举例的 XML
文档的节有:
<bookstore> (document node)
<author>J K. Rowling</author> (element node)
lang="en" (attribute node)
Atomic values
原子值
Atomic
values are nodes with no children or parent.
原子值是那些没有子或父的节(无上下关系)。
Example
of atomic values:
举例中的原子值:
J K. Rowling
"en"
Items
项目
Items
are atomic values or nodes.
项目是原子值或节。
Relationship of Nodes
节之间的关系
Parent/ 父
Each
element and attribute has one parent.
每个元素和属性有一父亲。
In
the following example; the book element is the parent of the title, author,
year, and price:
下面的举例中: book
元素是
title
, author
, year
和 price
的父亲
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Children/ 子
Element
nodes may have zero, one or more children.
元素节可能有 0
个或多个子
In
the following example; the title, author, year, and price elements are all
children of the book element:
下面的举例中: title,author,year
和 price
元素都是 book
元素的子元素
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Siblings/ 兄
Nodes
that have the same parent.
指那些有相同父的
In
the following example; the title, author, year, and price elements are all
siblings:
下面的举例中 title,
author, year,
和 price
元素都为兄弟
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
Ancestors/ 祖
A
node's parent, parent's parent, etc.
节的父,父的父 ....
都为祖
In
the following example; the ancestors of the title element are the book element
and the bookstore element:
下面的举例中: book
元素和
bookstore
元素都为 title
元素的祖元素
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Descendants/ 孙
A
node's children, children's children, etc.
节的子,子的子 ...
都为孙
In
the following example; descendants of the bookstore element are the book,
title, author, year, and price elements:
下面的举例中: bookstore
元素的孙有 book,title,author,year
以及 price
元素
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
XPath
语法
翻译: Linyupark / 2006-03-24
XPath
uses path expressions to select nodes or node-sets in an XML document. The node
is selected by following a path or steps.
XPath
使用路径表达式来选择 XML
文档的节或是节集。顺着路径或步骤来选择节。
The XML Example Document
XML
实例文档
We
will use the following XML document in the examples below.
举例中我们将使用下面的 XML
文档
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
Selecting Nodes
选择节
XPath
uses path expressions to select nodes in an XML document. The node is selected
by following a path or steps. The most useful path expressions are listed
below:
一些非常有用的路径表达式:
表达式 |
描述 |
nodename |
Selects all child nodes of the node[ 选择所有目前节的子节 ] |
/ |
Selects from the root node[ 从根节进行选择 ] |
// |
Selects nodes in the document from the current node that match the selection no matter where they are [ 选择文档中相吻合的节而不管其在文档的何处 ] |
. |
Selects the current node[ 选择当前节 ] |
.. |
Selects the parent of the current node[ 当前节的父节 ] |
@ |
Selects attributes[ 选择属性 ] |
Examples
实例
In
the table below we have listed some path expressions and the result of the
expressions:
下面我们所列举的表格有路径表达式以及其结果:
路径表达式 |
结果 |
bookstore |
Selects all the child nodes of the bookstore element[ 选择所有 bookstore 元素的子节 ] |
/bookstore |
Selects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an element! [ 选择了 bookstore 的根元素。注意:如果路径的开始为 (/) 那此路径一定是到该元素的绝对路径 ] |
bookstore/book |
Selects all book elements that are children of bookstore[ 选择了所有在 bookstore 的子元素 book 元素所包含的所有元素(其实就为 bookstore 里 book 元素所包含的元素) ] |
//book |
Selects all book elements no matter where they are in the document[ 选择所有为 book 元素的内容而不管 book 元素处于何处 ( 有不同的父也没关系 )] |
bookstore//book |
Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element[ 在 bookstore 元素内所有含有 book 元素的元素内容(只要 book 元素的祖元素为 bookstore 元素那都符合条件) ] |
//@lang |
Selects all attributes that are named lang[ 选择所有属性名为 lang 的属性 ] |
Predicates
谓语
Predicates
are used to find a specific node or a node that contains a specific value.
谓语用来指定明确的节所含有的特殊的值
Predicates
are always embedded in square brackets.
谓语被嵌入在中括号
Examples
举例
In
the table below we have listed some path expressions with predicates and the
result of the expressions:
下面的表格列举了一些使用了谓语的路径表达式以及其产生的结果:
路径表达式 |
结果 |
/bookstore/book[1] |
Selects the first book element that is the child of the bookstore element[ 选择了 bookstore 里的第一个 book 元素 ] |
/bookstore/book[last()] |
Selects the last book element that is the child of the bookstore element[ 选择 bookstore 里最后一个 book 元素 ] |
/bookstore/book[last()-1] |
Selects the last but one book element that is the child of the bookstore element[bookstore 中倒数第二个 book 元素 ] |
/bookstore/book[position()<3] |
Selects the first two book elements that are children of the bookstore element[ 在 bookstore 中前两个 book 元素 ] |
//title[@lang] |
Selects all the title elements that have an attribute named lang[ 选择所有含有 lang 属性的 title 元素 ] |
//title[@lang='eng'] |
Selects all the title elements that have an attribute named lang with a value of 'eng'[ 选择所有含有 lang 属性并且值为 eng 的 title 元素 ] |
/bookstore/book[price>35.00] |
Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00[ 选择所有 bookstore 中 book 元素里 price 元素内容大于 35.00 的 book 元素 ] |
/bookstore/book[price>35.00]/title |
Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00[ 选择 bookstore 中 book 的子元素 title ,并且其兄弟元素 price 的内容得大于 35.00] |
Selecting Unknown Nodes
选择未知的节
XPath
wildcards can be used to select unknown XML elements.
XPath
的通配符可以用来选择未知的 XML
元素
通配符 |
描述 |
* |
Matches any element node[ 相吻合的所有元素节 ] |
@* |
Matches any attribute node[ 相吻合的所有属性节 ] |
node() |
Matches any node of any kind[ 吻合任何类型的节 ] |
Examples 实例
In
the table below we have listed some path expressions and the result of the
expressions:
下面的表格我们将列举一些路径表达式以及它们的结果
路径表达式 |
结果 |
/bookstore/* |
Selects all the child nodes of the bookstore element[ 选择所有 bookstore 的子节 ] |
//* |
Selects all elements in the document[ 选择所有文档中的元素 ] |
//title[@*] |
Selects all title elements which have any attribute[ 选择元素为 title 并且其含有属性 ] |
Selecting Several Paths
选择数个路径
By
using the | operator in an XPath expression you can select several paths.
通过在 XPath
中使用
|
你可以选择数个路径
Examples
实例
In
the table below we have listed some path expressions and the result of the
expressions:
下面的表格我们会列举一些路径表达式以及其结果:
路径表达 |
结果 |
//book/title | //book/price |
Selects all the title AND price elements of all book elements[ 选择所有 book 里 title 和 price 元素 ] |
//title | //price |
Selects all the title AND price elements in the document[ 选择所有 title 和 price 元素 ] |
/bookstore/book/title | //price |
Selects all the title elements of the book element of the bookstore element AND all the price elements in the document[ 选择所有 book 里的 title 元素和所有 price 元素 ] |
XPath
轴
翻译: Linyupark / 2006-03-24
发表评论
-
理论与实践相结合 - 汽车早视网的诞生
2013-06-20 22:22 52工作也有三年时间了 ... -
舌尖上的社交电商
2012-06-09 15:01 191社交电商通俗的来讲就是基于社交网络的电子商务。 先说社交,现 ... -
【收藏】开源协议大全
2011-04-29 15:14 1205最近看了SparkWeb到开源协议为GPL。不是很了解协议具体 ... -
Windows下安装subversion
2011-01-06 00:14 1481前几天装SubVersion,在google上搜了一把,按国内 ... -
天下没有免费的午餐 ---- 360 的伪免费
2010-11-04 16:29 1196天下没有免费的午餐。。。有也不敢吃。。。或许。。。 360对腾 ... -
ASCII对照表
2010-10-27 09:33 1059收藏ASCII表备用。。 Bin ... -
狗日的腾讯原文 转自《计算机世界》
2010-08-03 10:27 20338以下文章出自《计算机世界》 “有什么业务是腾讯不做的吗 ... -
四批开源软件的“拿来主义”
2010-03-05 10:22 1026有人问, Linux 应该怎么搞( do ... -
赚钱不能靠蛮力--对淘宝客的一些建议
2010-02-06 11:47 1153随着淘宝的淘宝客 ... -
Google最常用1000关键字
2010-01-15 15:41 1347收藏版:::::: 下面是google最常用的1000 ... -
淘宝导购三个月,终于有收入了
2009-12-23 12:04 1835自己做淘宝导购差不多三个月了,先晾凉自己的部分收入报表。。。 ... -
做淘客一个月,pr升3
2009-10-31 13:21 386来淘宝了网上线一个多月了,淘客一个月,pr就升3了,还是 ... -
Google宣布不在使用Pagerank
2009-10-20 12:39 949由于最近做了个简单的网站来淘宝了网 ,所以最近比 ... -
同样的淘宝客不同的经历 做比想难
2009-10-16 11:45 1300虽然有很多人都在做淘宝客,不过真正做的好的并没有 ... -
自己弄了个淘宝导购网,嘿嘿
2009-09-27 13:42 1759自己做了一个淘宝导购网,下面谈谈自己的个人经历: ...
相关推荐
XPath语法详细介绍 XPath语法详细介绍 XPath语法详细介绍 XPath语法详细介绍 XPath语法详细介绍
主要介绍了Python3 xml.etree.ElementTree支持的XPath语法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
C#对xml中关于使用xpath语法的介绍
xpath语法
xpath语法与函数
爬虫xpath 应用于浏览器的一个插件,便于帮助书写xpath路径
XPath 简单语法XPath 简单语法XPath 简单语法XPath 简单语法XPath 简单语法XPath 简单语法
来源:MSDN 包含XPath语法、运算符、示例。
XPath语法简要说明1
对XPath语法进行了详细的讲解。XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。开发人员必备
NULL 博文链接:https://z-one.iteye.com/blog/1172949
astpath:一个命令行工具用于使用XPath语法查询Python ASTs
介绍XSL语法中Xpath的使用方法
Xpath生成器,自动生成可用的Xpath
不可多得的xpath实例语法教程,里面有详细的实例,是学习xpath的好助手。同时还提供了IBM等大公司都在使用的xpath操作选择路径的观察器及验证器,该观察器及验证器功能很强大,你只要输入xpath查找路径,验证器会...
整理JsoupXpath( https://github.com/zhegexiaohuozi/JsoupXpath)是一款纯Java开发的使用xpath解析提取html内容的解析器,xpath语法分析与执行...JsoupXpath的实现逻辑清晰,扩展方便, 支持几乎全部常用的xpath语法。
2、理解XPath的类型系统和序列类型等相关概念,掌握XPath表达式语法和执行语义,能够熟练地、灵活地运用各种关系轴、判定谓词和XPath基本函数编写查询表达式。 3、掌握XSLT文档中基本语法单元的使用,比如模板的定义...
主要给大家介绍了关于Python爬虫基础之XPath语法与lxml库用法的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
一个用webservice和jquery 编写的XPATH语法测试的网页文件