The XPath language is a tree representation of XML documents. It allows the user to navigate around the document’s tree, selecting nodes by various criteria.
Originally created to provide a common language and behavior model between XSLT and XPointer, XPATH is often used in other W3C standards
For the below XML.,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?xml version="1.0"?> <catalog> <book id="6260"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="2526"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> </catalog> |
The XPATH to find the author for the book id:6260 is
/catalog/book[@id = ‘6260’]/author
The XPATH to find the price for the book id:6260 is
catalog/book[@id = ‘6260’]/price (or) catalog/book[1]/price
The book[1] denotes the first child of the book element which can be appear more than one.,