Writing XPath expressions
XPath describes a path through the XML document, similar to a path to a file on a disk. Consider the following piece of XML:
<catalog>
<product>
<nr>12345</nr>
<description>Chair</description>
</product>
<product>
<nr>30250</nr>
<description>Table</description>
</product>
</catalog>
If we want to select the product elements in this XML document, we can use the following XPath expression:
/catalog/product
The slash ( / ) at the beginning of the expression makes this an absolute path, starting at the document root. If we trace the path from the document root to the product nodes, we first encounter a catalog element and then the product element. Hence the XPath.