50%

XPath Tester

Ln: 1 Col: 0

Upload data using file or url

XPath Expression

Sample XML data with NameSpace Try it.

<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>

Ln: 1 Col: 0

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)

Online XPath Tester


XPath Tester helps developers, testers, and data scientists write, test, and refine XPath Expressions for XML or HTML Data.

What can you do with XPath Tester?

  • It helps Real-Time Validation by instantly seeing the results of XPath Queries which allows to do quick adjustments without running full scripts.
  • This will reduce Errors by identifying and fixing syntax or structural issues in expressions before deploying in a production environment.
  • For Learning, this will help to gain a deeper understanding of XPath by applying different types of queries and how they produce the result.

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.
  • 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.

Related Tools


Recently visited pages


Tags


XML