In Firefox JavaScript console:
parser = new DOMParser();
foo = parser.parseFromString(\' \', \"text/xml\");
res = foo.evaluate(\"/foo\
You have to do two things when dealing with namespaces.
ns
-- better go with something more descriptive in real world code.evaluate(...)
.Putting everything together, your code would look like this:
parser = new DOMParser();
foo = parser.parseFromString(' ', "text/xml");
res = foo.evaluate("/ns:foo", foo, function(prefix) {
if (prefix === 'ns') {
return 'http://foo.bar.baz/quux';
} else {
return null
}
}, 0, null);
res.iterateNext();
Which returns as expected:
Your third query has results because you're using the wildcard matcher *
which ignores namespaces. An alternative XPath expression without registering a namespace, but using the wildcard matcher would be
//*[local-name() = 'foo']