XPath Validator

Validate your XPath expressions/queries against a XML file. Supports most of the XPath functions: string(), name(),number(), string-length() etc.

Input XML






XPath expression


Output





XPath Examples

All of the examples bellow are using this sample XML code. You can find more examples and explanation on XPath expressions at W3Schools.com

1. Select the document node
/
2. Select the 'root' element
/root
3. Select all the elements in the document.
//*
4. Select all 'car' elements that are children of the 'cars' element.
/root/cars/car
5. Select all 'plane' elements regardless of their positions in the document.
//plane
6. Select the 'id' attributes of the 'plane' elements regardless of their positions in the document.
//plane/@id
7. Select the text value of first 'car' element.
//car[1]/text()
8. Select the last 'car' element.
//car[last()]
9. Select the first and second 'car' elements using their position.
//car[position() < 3]
10. Select all 'car' elements that have an 'id' attribute.
//car[@id]
11. Select the 'car' element with the 'id' attribute value of '3'.
//car[@id='3']
12. Select all 'car' nodes with the 'id' attribute value lower or equal to '3'.
//car[@id<=3]
13. Select all the children of the 'planes' node.
/root/planes/*
14. Select all the 'car' elements AND the 'plane' elements.
//car|//plane
15. Select the numeric value of the 'id' attribute of the first 'car' element.
number(//car[1]/@id)
16. Select the name of the first element in the document.
name(//*[1])
17. Select the string representation value of the 'id' attribute of the first 'car' element.
string(//car[1]/@id)
18. Normalize the string by ignores the leading, trailing, and repeating white spaces
normalize-space()
19. Select the sum of the 'id' attributes of the 'plane' elements.
sum(//plane/@id)
20. Select the number of 'plane' elements.
count(//plane)
21. Select the length of the first 'car' element's textual value.
string-length(//car[1]/text())