XPath Tester

XML Input

Option 1: Copy-paste your XML string hereSample
Option 2: Or Load your XML file

XPath Expression



Close
Result Full Screen

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)

XPath Tester



This is an online tool that is used by developers and programmers to evaluate and test XPath. In another definition it is a tool which helps to test your expressions or queries against XML data file and URL. It is used to validate and extract the matching piece of the XML data against the input expression and its simple interface allows users to navigate the page easily so as to get the desired result.


How Do I Use an XPath Tester?



Input your XML String in the appropriate box Click on TEST XPath and watch your results being displayed in the opposite box. OR Click on Load URL input your URL and test your XPath.


Do you know..?

Sample URL
Title
Description
Tags

By clicking the "Save Online" button you agree to our terms and conditions.