Reputation: 3528
I am using http://xpath.online-toolz.com/tools/xpath-editor.php as an online XPath evaluator. I tried a few others but it's all the same
I have the following in my xml :-
<?xml version="1.0"?>
<test xmlns="abc">
</test>
Now the XPath queries
/
.
gives me the output :-
<test xmlns="abc">
</test>
However, the queries
test
/test
//test
Do not give me any output at all. I'm doing a very basic mistake but I can't figure out what. I think it's got something to do with namespaces but changing the queries to
abc:test
doesn't help either because it gives an Invalid Expression error.
I'm using http://www.w3schools.com/xpath http://www.tizag.com/xmlTutorial/xpathtutorial.php & http://oreilly.com/perl/excerpts/system-admin-with-perl/ten-minute-xpath-utorial.html
as my sources for XPath tutorials.
Upvotes: 0
Views: 162
Reputation: 38073
You have no explicit namespace prefixes in your target file, but you still need to cater for them. You can write
/*[local-name()='test' and namespace-uri()='abc']
Your "abc" is a namespaceURI, not a namespace prefix. It is probably invalid as most tools will test it for a URI form such as
http://www.abc.com/
A better file would be:
<test xmlns="http://www.abc.com">
</test>
when your query would be:
/*[local-name()='test' and namespace-uri()='http://www.abc.com/']
I have tested this on your site and it works.
The form
abc:test
will depend on a mechanism to set the prefix abc
to 'http://www.abc.com/'
and there doesn't seem to be a mechanism on the site
Upvotes: 1