XPATH EXAMPLE
<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<employees>
<employee id="1">Johnny Dapp</employee>
<employee id="2">Al Pacino</employee>
<employee id="3">Robert De Niro</employee>
<employee id="4">Kevin Spacey</employee>
<employee id="5">Denzel Washington</employee>
</employees>
<foo:companies>
<foo:company id="6">Tata Consultancy Services</foo:company>
<foo:company id="7">Wipro</foo:company>
<foo:company id="8">Infosys</foo:company>
<foo:company id="9">Microsoft</foo:company>
<foo:company id="10">IBM</foo:company>
<foo:company id="11">Apple</foo:company>
<foo:company id="12">Oracle</foo:company>
</foo:companies>
</root>
XPATH TEST CASES
1. Select the document node /
2. Select the 'root' element /root
3. Select all 'employee' elements that are direct children of the 'employees' element. /root/employees/employee
4. Select all 'company' elements regardless of their positions in the document. //foo:company
5. Select the 'id' attributes of the 'company' elements regardless of their positions in the document. //foo:company/@id
6. Select the textual value of first 'employee' element. //employee[1]/text()
7. Select the last 'employee' element. //employee[last()]
8. Select the first and second 'employee' elements using their position. //employee[position() < 3]
9. Select all 'employee' elements that have an 'id' attribute. //employee[@id]
10. Select the 'employee' element with the 'id' attribute value of '3'. //employee[@id='3']
11. Select all 'employee' nodes with the 'id' attribute value lower or equal to '3'. //employee[@id<=3]
12. Select all the children of the 'companies' node. /root/foo:companies/*
13. Select all the elements in the document. //*
14. Select all the 'employee' elements AND the 'company' elements. //employee|//foo:company
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 'employee' element. number(//employee[1]/@id)
17. Select the string representation value of the 'id' attribute of the first 'employee' element. string(//employee[1]/@id)
18. Select the length of the first 'employee' element's textual value. string-length(//employee[1]/text())
19. Select the local name of the first 'company' element, i.e. without the namespace. local-name(//foo:company[1])
20. Select the number of 'company' elements. count(//foo:company)
21. Select the sum of the 'id' attributes of the 'company' elements. sum(//foo:company/@id)