Is there a way to get the prefix / namespace bindings used in a XML document preferably using standard org.w3c.org
and javax.xml
APIs? I understand that prefixes may by re-defined in contained elements so the API should be able to account for that as well.
I am looking for a code snipped that would take an XML document in some serialized form and return a Map<String, String>
of prefix to URI name bindings (plus some extra cleverness in the API to account for redefinitions in enclosed elements). Ideally a library might be able to do fancier stuff such as identify / purge unused bindings, move duplicate bindings to their nearest common ancestor (instead of having them replicated all over the place) and so on.