# XPath

This section describes XPath expressions that you can use with Talend Cloud API Tester.

For more information on the [XPath syntax](https://www.w3schools.com/xml/xpath_syntax.asp), see the [official W3C specification](https://www.w3.org/TR/xpath/). You can also find an online XPath evaluator on the [Free Formatter website](https://www.freeformatter.com/xpath-tester.html). Note that XPath expressions have a directory-path-like syntax.

Here are a few tips to help you work with XML payloads:

* A single / selects from the root node.
* /list identifies the "list object" at the top level of the XML document. Then you can iterate over attributes and sub attributes. The language natively supports arrays.
* The slash sign / allows you to get attributes of an object or to go deeper in the tree.
* The square brackets [] enable to select a specific item in an array by its position. Please note that the index starts from 1.
* /text() allows you to get a node inner text.
* // selects nodes in the document from the current node that match the selection no matter where they are.

## Sample XPath expressions

```
  <?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>

  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>

  <book category="web">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>
    <year>2003</year>
    <price>49.99</price>
  </book>

  <book category="web">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>
```

Here are some sample expressions and their result.

| Expression | Value |
| --- | --- |
| / | The whole document node |
| /bookstore | The bookstore node |
| /bookstore/book/title | An array of all title nodes of all book nodes under the<br>bookstore element |
| //title | An array of all title nodes whatever their position<br>is |
| //title/@lang | An array of all lang attributes of the<br>title nodes |
| /bookstore/book/title/text() | An array of all text values of title nodes of all "book"<br>nodes under the bookstore element |
| /bookstore/book[price&gt;35]/title | The title nodes of all book nodes having<br>price greater than 35 |
| //book[last()]/title | The title node of the last book<br>node |
| //book[position() &lt; 3] | The first two book nodes |
| //title[@lang]] | An array of all title nodes with an attribute<br>lang |
| name(//\*[1]) | The name of the first element in the document (i.e.:<br>bookstore) |
| count(//title) | The number of all title nodes (i.e.:<br>4) |

### In this section

* [XML namespace issue](https://help.qlik.com/talend/en-US/api-tester-user-guide/Cloud/xml-namespace-support)