a toolbox for the web.

XPath Tester / Evaluator

To use this free online XPath tester paste your code into the editor on the left or upload using the options below.

What is this tool?

It is a simple online tool that you can use to test XPath expressions against your XML code. It supports features found in XPath 1.0 and 2.0.

To begin using this tester paste your XML into the editor on the left or use the options below to upload a file from your computer or a location on the internet.

You can then type your expressions in and click the "test" button to see the result in the editor on the right.

XML Code and Expression Examples

Below is XML code and a list of working XPath expressions to demonstrate how one could extract different elements of information from it.

<root xmlns:foo="http://www.foo.org" xmlns:bar="http://www.bar.org">
	<cast>
		<actor id="1">Ted Levine</actor>
		<actor id="2">Kathleen Quinlan</actor>
		<actor id="3">Dan Byrd</actor>
		<actor id="4">Emilie de Ravin</actor>
		<actor id="5">Aaron Stanford</actor>
		<actor id="6">Vinessa Shaw</actor>
		
	</cast>
	<writers>
		<writer id="1">Wes Craven (based upon his film)</writer>
		<writer id="2">Alexandre Aja (screenplay)</writer>
	</writers>
	<foo:crew>
		<director id="5">Alexandre Aja</director>
	</foo:crew>
</root>
Expression
Use
//*
select all the elements in the document.
/root
selects the "root" elements and all of its outer HTML
/root/cast/actor
selects all of the "actor" elements contained directly within the "cast" element
//foo:crew
select all "foo:crew" elements regardless of their positions in the document.
//foo:crew/@id
select the "id" attributes of the "crew" elements regardless of their positions in the document.
//cast[1]/text()
select the textual value of first "cast" element.
//actor[last()]
select the last "actor" element.
//actor[position() < 3]
select the first and second "actor" elements using their position.
//actor[@id]
select all 'actor' elements that have an "id" attribute.
//actor[@id='//actor[@id='2']']
select the "actor" element with the "id" attribute value of "2".
//actor[@id<=3]
select all 'actor' nodes with the 'id' attribute value lower or equal to '3'.
/root/foo:writers/*
select all the children of the "writers" node.
name(//*[1])
select the name of the first element in the document.
number(//actor[1]/@id)
select the numeric value of the 'id' attribute of the first 'actor' element.
string(//actor[1]/@id)
select the string representation value of the 'id' attribute of the first 'actor' element.
string-length(//actor[1]/text())
select the length of the first 'actor' element's textual value.
count(//writer)
Select the number of 'writer' elements.