Why is there no XPath syntax for namespace-qualified nodes?

Joshua Fox picture Joshua Fox · Aug 14, 2011 · Viewed 7.6k times · Source

Some of the nodes in an XML document have namespaces, specified with a defined prefix.

It is possible to specify local-name() in XPath 1.0 and so ignore namespaces.

However, I want to enable the writer of the XPath to find nodes using their full namespace-qualified name as an identifier.

The recommended way is to add namespace declarations in the invoking code (in my case, Java). But this means that the person writing Xpath does not have the ability to work with namespaces!

How do we find nodes by their fully qualified names using pure XPath?

Answer

LarsH picture LarsH · Aug 14, 2011

Not sure what you meant by "as an identifier".

How do we find nodes by their fully qualified names using pure XPath?

In XPath 1.0, by using local-name() and namespace-uri(), e.g.

"*[local-name() = 'foo' and namespace-uri() = 'http://my.org/ns/2.0']"

In XPath 2.0, there is a richer set of functions related to namespaces, e.g. namespace-uri-from-QName(). But I'm not sure they improve on the above for what you want.