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)

What else can I do with XPATH TESTER ?

  • The XPath tester fully supports XML namespaces, but the declarations MUST be explicit and MUST be on the root XML element. See the XPath Examples section for details.
  • Allows you to test your XPath expressions/queries against an XML file. This tool runs better than other existing XPath online tools as it supports most of the XPath functions (string(), number(), name(), string-length() etc.) and does not limit you to working against nodes.
  • You can choose to also include the XML item type (Attribute, Element, Text, etc.) as part of the output. This allows you to better understand which parts were matched.

Do you know..?


Copyright © CodeBeautify 2021 | v9.1

Sample URL
Title
Description
Tags

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