分类:
2012-12-19 18:06:03
xpath学习整理
时间:
|
表达式 |
含义 |
|
./author |
当前上下文中的所有 |
|
author |
当前上下文中的所有 |
|
first.name |
当前上下文中的所有 |
|
/bookstore |
本文档的文档元素( |
|
//author |
本文档中的所有 |
|
book[/bookstore/@specialty
= @style] |
style
属性值等于文档根目录的 |
|
author/first-name |
属于 |
|
bookstore//title |
|
|
bookstore/*/title |
属于 |
|
bookstore//book/excerpt//emph |
|
|
.//title |
当前上下文中更深的一级或多级的所有 |
|
author/* |
属于 |
|
book/*/last-name |
属于 |
|
*/* |
当前上下文的所有孙级元素。 |
|
*[@specialty] |
具有 specialty 属性的所有元素。 |
|
@style |
当前上下文的 style 属性。 |
|
price/@exchange |
当前上下文中 |
|
price/@exchange/total |
返回空节点集,因为属性不包含元素子级。XML 路径语言 (XPath) 语法允许使用此表达式,但是严格意义上讲无效。 |
|
book[@style] |
当前上下文的具有 style 属性的所有 |
|
book/@style |
当前上下文的所有 |
|
@* |
当前元素上下文的所有属性。 |
|
./first-name |
当前上下文节点中的所有 |
|
first-name |
当前上下文节点中的所有 |
|
author[1] |
当前上下文节点中的第一个 |
|
author[first-name][3] |
具有 |
|
my:book |
my
命名空间中的 |
|
my:* |
my
命名空间中的所有元素。 |
|
@my:* |
my
命名空间中的所有属性(不包括 my 命名空间中的元素的未限定属性)。 |
|
|
|
|
book[last()] |
当前上下文节点的最后一个 |
|
book/author[last()] |
当前上下文节点的每个 |
|
(book/author)[last()] |
当前上下文节点的 |
|
book[excerpt] |
至少包含一个 |
|
book[excerpt]/title |
属于 |
|
book[excerpt]/author[degree] |
至少包含一个 |
|
book[author/degree] |
所有包含 |
|
author[degree][award] |
至少包含一个 |
|
author[degree
and award] |
至少包含一个 |
|
author[(degree
or award) and publication] |
至少包含一个 |
|
author[degree
and not(publication)] |
至少包含一个 |
|
author[not(degree
or award) and publication] |
至少包含一个 |
|
author[last-name
= "Bob"] |
至少包含一个值为 Bob 的 |
|
author[last-name[1]
= "Bob"] |
第一个 |
|
author[last-name
[position()=1]= "Bob"] |
第一个 |
|
degree[@from
!= "Harvard"] |
from
属性不等于
"Harvard" 的所有 |
|
author[.
= "Matthew Bob"] |
所有值为 Matthew Bob 的 |
|
author[last-name
= "Bob" and ../price > 50] |
包含值为 Bob 的 |
|
book[position()
<= 3] |
前三本书(1、2、3)。 |
|
author[not(last-name
= "Bob")] |
不包含值为 Bob 的 |
|
author[first-name
= "Bob"] |
至少包含一个值为 Bob 的 |
|
author[*
= "Bob"] |
所有包含任何值为 Bob 的子元素的 author 元素。 |
|
author[last-name
= "Bob" and first-name = "Joe"] |
所有包含值为 Bob 的 |
|
price[@intl
= " |
上下文节点中所有 intl 属性等于 "Canada" 的 |
|
degree[position()
< 3] |
属于上下文节点子级的前两个 |
|
p/text()[2] |
上下文节点中每个 |
|
ancestor::book[1] |
与上下文节点最接近的 |
|
ancestor::book[author][1] |
与上下文节点最接近的 |
|
ancestor::author[parent::book][1] |
当前上下文中最接近的 |
|
|
|
|
|
|
|
|
|
|
|
|