title: get prefix / namespace bindings used in an XML document preferably using org.w3c.dom and javax.xml APIs
body: <p>Is there a way to get the prefix / namespace bindings used in a XML document preferably using standard <code>org.w3c.org</code> and <code>javax.xml</code> APIs? I understand that prefixes may by re-defined in contained elements so the API should be able to account for that as well.</p>
  
  <p>I am looking for a code snipped that would take an XML document in some serialized form and return a <code>Map&lt;String, String&gt;</code> 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.</p>