XPath is a major element in W3C's XSLT standard, it is used to navigate through attributes and elements in an XML document. It can also be used to test document's addressed nodes to determine whether they match a pattern or not.
How do I use the tool?
1. Select the document node
/
2. Select the 'root' element
/root
3. Select all 'celebrity' elements that are direct children of the 'celebritys' element.
/root/celebritys/celebrity
4. Select all 'artist' elements regardless of their positions in the document.
//foo:artist
5. Select the 'id' attributes of the 'artist' elements regardless of their positions in the document.
//foo:artist/@id
6. Select the textual value of first 'celebrity' element.
//celebrity[1]/text()
7. Select the last 'celebrity' element.
//celebrity[last()]
8. Select the first and second 'celebrity' elements using their position.
//celebrity[position() < 3]
9. Select all 'celebrity' elements that have an 'id' attribute.
//celebrity[@id]
10. Select the 'celebrity' element with the 'id' attribute value of '3'.
//celebrity[@id='3']
11. Select all 'celebrity' nodes with the 'id' attribute value lower or equal to '3'.
//celebrity[@id<=3]
12. Select all the children of the 'singers' node.
/root/foo:singers/*
13. Select all the elements in the document.
//*
14. Select all the 'celebrity' elements AND the 'artist' elements.
//celebrity|//foo:artist
15. Select the name of the first element in the document.
name(//*[1])
16. Select the numeric value of the 'id' attribute of the first 'celebrity' element.
number(//celebrity[1]/@id)
17. Select the string representation value of the 'id' attribute of the first 'celebrity' element.
string(//celebrity[1]/@id)
18. Select the length of the first 'celebrity' element's textual value.
string-length(//celebrity[1]/text())
19. Select the local name of the first 'artist' element, i.e. without the namespace.
local-name(//foo:artist[1])
20. Select the number of 'artist' elements.
count(//foo:artist)
21. Select the sum of the 'id' attributes of the 'artist' elements.