XPath 笔记

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

操作符:

 

OperatorDescriptionExampleReturn 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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值