How do I use XPath with XML namespace - VisualCron - Forum

Community forum

ErikC
  •  ErikC
  • Paid support Topic Starter
2012-08-15T10:14:10Z
If you have an XML file which includes a namespace you have to use a prefix in your XPath expression.

Here you have a sample XML file with a namespace: http://someurl.org/2012 

<?xml version="1.0" encoding="utf-8"?>
<test attribute1="nothing here" xmlns="http://someurl.org/2012">
<book>
<name>title1</name>
</book>
<book>
<name>title2</name>
</book>
</test>


Normally you should use /test[1]/book[2]/name[1] to get the title2 as result.
Now with the namespace in the XML file, add the namespace in the Namespaces list and add a prefix, e.g. x.

You should change the XPath expession to: /x:test[1]/x:book[2]/x:name[1]
Now you get the title2 as result.
ErikC attached the following image(s):

Uses Visualcron since 2006.
Scroll to Top