常见使用方法的例子,作为参考:
对于网络应用,有不同的使用方法。对于仅将XML文件作为数据库存储的一种方式,使用:
XmlDoc.selectNodes(xpath);
例子:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
(1)选取所有的title
/bookstore/book/title(2)选取第一个book的title
/bookstore/book[1]/title(3)选区price节点中的恶所有文本
/bookstore/book/price/text()(4)选取价格高于35的所有price节点或title节点
/bookstore/book[price>35]/price
/bookstore/book[price>35]/title
参考:
http://www.w3school.com.cn/xpath/xpath_examples.asp