< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>
Xpath是一种能够在XML文档中寻找信息的语言。它通过XML文档中的元素和属性来进行导航。
1. "/"
/AAA:
<AAA>
<BBB/>
<CCC/>
<DDD>
<BBB/>
<CCC/>
<AAA>
/AAA/CCC:
<AAA>
/AAA/DDD/BBB:
<AAA>
2. "//"
//BBB
<BBB/>
<CCC>
<DDD>
<BBB/>
//DDD/BBB
<AAA>
DDD>
3. "*":
/AAA/CCC/DDD*/*/BBB
<AAA>
<XXX>
<EEE/>
<FFF/>
<DDD>
<BBB>
<BBB>
<BBB/>
<BBB>
<BBB>
<CCC>
//*
<FFF/>
DDD>
XXX>
CCC>
AAA>
4. [1] , last()
/AAA/BBB[1]
/AAA/BBB[last()]
5. "@" :
//@id
<BBB id = "b1"/>
<BBB id = "b2"/>
<BBB name = "bbb"/>
//BBB[@id]
//BBB[@name]
//BBB[@*]
//BBB[not(@*)]
//BBB[@id='b1']
<BBB name = " bbb "/>
//BBB[@name='bbb']
//BBB[normalize-space(@name)='bbb']
<BBB name = " bbb "/>
6. count() :
//*[count(BBB)=2]
CCC>
<EEE>
<CCC/>
<DDD/>
EEE>
//*[count(*)=2]
//*[count(*)=3]
本文转自 netcorner 博客园博客,原文链接:http://www.cnblogs.com/netcorner/archive/2006/11/09/2912521.html ,如需转载请自行联系原作者