Reputation: 7441
I'm trying to get the xmlns:attr
attribute value from this XML using XPath. I can't seem to get it.
<a:b xmlns:attr="value">
</a:b>
This is from the root node.
I've tried just about every combination, but I can't seem to find anything that works.
Upvotes: 4
Views: 2040
Reputation: 111491
Setting aside the distraction of the undeclared a:
namespace, let's instead use this example:
<b xmlns:attr="value"/>
Note: Your name choice of attr
belies the fact that in the above XML, attr
is not an attribute but rather is a namespace prefix.
Use the namespace
axis:
/b/namespace::attr
will evaluate to
value
According to XML Path Language (XPath) 2.0 (Second Edition):
In XPath Version 2.0, the namespace axis is deprecated and need not be supported by a host language.
Instead, use the namespace-uri-for-prefix()
:
/b/namespace-uri-for-prefix('attr',.)
will evaluate to
value
Upvotes: 6