Reputation: 505
What i'm working on is: I have an xml-tree and i rebuild it with some small changes in a second xml-tree (I don't make any changes on the old tree). Here's an example of the xml-code i'm currently working on.
<foo xmlns="http://some.name/space"
xmlns:ns2="http://some.other/name/space"
schemaLocation="http://some.name/space ../../Schema1.xsd
http://some.other/name/space ../../Schema2.xsd
http://third.name/space ../../Schema3.xsd">
<bar xsi:type="ns2:ApplePie">
<ns2:apple xmlns:ns3="http://third.name/space">
<ns3:choclate name="Lindt" form="round">
<ns3:blackChoclate xsi:type"ns3:YummyBlackChoclate">
...
</ns3:blackChoclate>
</ns3:choclate>
</ns2:apple>
</bar>
</foo>
When i've got the Element
that represents <ns3:blackChoclate>
I want to find out which prefixes+namespaces are defined at that point.
I want to know that because i have to move the black Choclate element to some other place in the new xml-tree and for that i need to know which of the used prefixes are defined later than in the foo
element.
Currently i'm just going "upwards" through the tree with .getParentNode(...)
and search for xmlns:...
attributes, but i wanted to know if there's an easier way to find out which prefixes+namespaces are defined at that point.
Upvotes: 0
Views: 128
Reputation:
The only way of achieving this is to keep track of the namespaces and prefixes in a map while iterating over the dom-document!
You should have a HashMap holding the prefix as key and a list of Strings for the namespaces (list because you can redefine prefixes!)
Upvotes: 1