xpath的語法 (轉載自:http://www.cnblogs.com/jianjialin/archive/2009/02/01/1382056.html
XPath 是XML的查詢語言,和SQL的角色很類似。以下面XML爲例,介紹XPath 的語法。
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd></catalog>
</catalog>
定位節點
XML是樹狀結構,類似檔案系統內數據夾的結構,XPath也類似檔案系統的路徑命名方式。不過XPath 是一種模式(Pattern),可以選出 XML檔案中,路徑符合某個模式的所有節點出來。例如要選catalog底下的cd中所有price元素可以用: