Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Below are some examples of most common scenarios for XML path expressions.


Code Block
<?xml version="1.0"?>
   <book id="book1">
      <author>Author Name 1</author>
      <title>Book Title 1</title>
      <genre>Book Genre</genre>
      <description>Book Description...</description>
   <book id="book2">
      <author>Author Name 2</author>
      <title>Book Title 2</title>
      <genre>Book Genre</genre>
      <description>Book Description ...</description>


  1. Accessing Node Attribute (Id of first book)
    1. XPath Expression: /catalog/book[1]/@id
    2. Value: book1
  2. Accessing Node Text Content (Author of first book)
    1. XPath Expression: /catalog/book[1]/author/text()
    2. Value: Author Name 1

Now, if you are having XML namespaces defined in the XML file as below:

Code Block
<?xml version="1.0" encoding="utf-8"?>
  <hello:table xmlns:table="">
      <td>Hello world!!!!</td>

In the above XML, to access the td element, you may provide the below XPath expressions:

  1. /sample/*[local-name()='table' and namespace-uri()='']/tr/td/text()
  2. /sample/*[local-name()='table']/tr/td/text()