XpatherTester.com is the current “go to” tool I use when I want to test XPath (online and for free). I prefer the one built-in to Stylus Studio, but that’s a paid for product that I cannot install on each client’s computer.

To actually learn XPath, I suggest the W3Schools site: http://www.w3schools.com/xsl/xpath_intro.asp

To test the tool, you can copy/paste a sample XML from here: https://msdn.microsoft.com/en-us/library/ms762271%28v=vs.85%29.aspx

Step 1 – Paste in your XML to the tool


Step 2- Type in your XPath

For example, I typed in //book/title below. I have highlighted in yellow, because at first, it’s not intuitively obvious where to actually type in the XPath. Note: Do not type in the XPath in the Namespaces: box!


Step 3- View your results

The tool will leave your original XML on one tab of your browser, then the results will be opened in a new tab on your browser. This picture shows the original tab on the left, and the new tab on the right.

Note that the “” xml wrapper is added to keep the results as well-formed XML. When you run your XPath in C# or other tools, that will not happen.


Step 4- Retry as needed

When doing a complicated XPath, you might have to try several times. Close the results tab in your browser, and go back to your original tab to try again.

If you want to specify something like //ns1:books you can define namespace ns1 in the namespaces textarea at the top of the screen.  I haven’t placed with that much.  I tend to create XPath that uses the “localname” syntax, which is a little more difficult.  Use of this syntax is explained well on this StackOverflow page: http://stackoverflow.com/questions/10813653/xpath-select-node-based-in-a-condition-with-local-name.

For example:


Additional XPATH resources/samples for dealing with local-name and namespaces

Here are some old posts of mine when learning to do XPath back in 2004, it hasn’t really changed since then:

  1. http://www.stylusstudio.com/SSDN/default.asp?action=9&fid=23&read=3074
  2. http://www.stylusstudio.com/SSDN/default.asp?action=9&read=5018&fid=48&FirstTopic=1420&LastTopic=1439&style=WebBoard

Filed under: XPATH