I am looking for an XPath Expression to get the default namespace of a node.
My XML document might look like this.
<aaa>
<bbb xmlns="ns1" xmlns:ggg="ns2" attribute="value" attribute2="value2">
<ccc />
</bbb>
<bbb xmlns="ns4" xmlns:ggg="ns5" attribute="value" attribute2="value2">
<ddd />
</bbb>
</aaa>
I want to get ns1. I've tried it with the following expressions but none of it worked (I'm programming in Java 1.7 (so it is XPath 1.0) and tested with the online XPath visualizer on http://chris.photobooks.com/xml/default.htm).
/aaa/*[name()='bbb' and position()=1]/attribute::*
This expression only selects the attribute- and the attribute2-nodes.
/aaa/*[name()='bbb' and position()=1]/namespace::*
This expression does not select anything.
I would be grateful if someone has a hint for me.