ITeye博客

XPath 笔记

Kyll · 2008-03-22 09:39 · ML & Script & Style & Other... · Markdown

XPath 有 7 种节点:
element(元素)
attribute(属性)
text(文本)
namespace(命名空间)
processing-instruction(处理说明)
comment(注释)
document (root) nodes(文档节点或根节点)

属性值或文本, 是原子值。

每个元素或属性有一个父。
元素的子元素可以有 0 个, 1 个, 或者多个。
拥有同样父元素的成为兄弟。
元素的最顶级父, 称为祖先。
元素的子元素, 子元素的子元素等等, 称为子孙。

路径实例:
/bookstore/book[1]
/bookstore/book[last()]
/bookstore/book[last()-1]
/bookstore/book[position()<3]
//title[@lang]
//title[@lang='eng']
/bookstore/book[price>35.00]
/bookstore/book[price>35.00]/title
/bookstore/*
//*
//title[@*]
//book/title | //book/price
//title | //price
/bookstore/book/title | //price

绝对路径:
/step/step/...
相对路径:
step/step/...

轴实例:
child::book
attribute::lang
child::*
attribute::*
child::text()
child::node()
descendant::book
ancestor::book
ancestor-or-self::book
child::*/child::price

操作符:

 

Operator Description Example Return value | Computes two node-sets //book | //cd Returns a node-set with all book and cd elements + Addition 6 + 4 10 - Subtraction 6 - 4 2 * Multiplication

6 * 4

24 div Division 8 div 4 2 = Equal price=9.80 true if price is 9.80
false if price is 9.90 != Not equal price!=9.80 true if price is 9.90
false if price is 9.80 < Less than price<9.80 true if price is 9.00
false if price is 9.80 <= Less than or equal to price<=9.80 true if price is 9.00
false if price is 9.90 > Greater than price>9.80 true if price is 9.90
false if price is 9.80 >= Greater than or equal to price>=9.80 true if price is 9.90
false if price is 9.70 or or price=9.80 or price=9.70 true if price is 9.80
false if price is 9.50 and and price>9.00 and price<9.90 true if price is 9.80
false if price is 8.50 mod Modulus (division remainder) 5 mod 2 1

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。