Reputation: 11
Given the following xml snippets:
<ns2:Invoice xmlns="http://defaultnamespace.com" xmlns:ns2="http://namespace2.com"
xmlns:ns3="http://namespace3.com">
.........
</ns2:Invoice>
and:
<ns3:Invoice xmlns="http://defaultnamespace.com" xmlns:ns2="http://namespace2.com"
xmlns:ns3="http://namespace3.com">
.........
</ns3:Invoice>
Can xpath be used to get the namespace associated with the root (<Invoice>
) element?
Expected results would be as follows: In the first example, the root is prefixed "ns2" so I would expect "http://namespace2.com" In the second example, the root is prefixed "ns3" so I would expect "http://namespace3.com"
Upvotes: 1
Views: 1180
Reputation: 167781
You can use namespace-uri(/*)
, see http://www.w3.org/TR/xpath/#function-namespace-uri.
Upvotes: 5