Skip to content
XML

XPath

Path expressions for selecting nodes.

#xpath#query

Code

xml
<!-- Source document -->
<library>
  <book id="b1" category="fiction">
    <title lang="en">Dune</title>
    <author>Frank Herbert</author>
  </book>
  <book id="b2" category="science">
    <title lang="en">Cosmos</title>
    <author>Carl Sagan</author>
  </book>
</library>

<!-- XPath expressions:
  /library/book[1]              first book
  //author                      all authors anywhere
  /library/book[@id='b2']       book whose id is b2
  //title[@lang='en']           titles with lang=en
  /library/book[@category='science']/title
-->