code: private static void getNamespaceBindings(Element element, Map<String, String> namespaceMap) {
      if (element == null) {
        return;
      }
      NamedNodeMap attrs = element.getAttributes();
      for (int i = 0; i < attrs.getLength(); i++) {
        Node node = attrs.item(i);
        String name = node.getNodeName();
        if ((name != null && (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || name.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")))) {
          namespaceMap.put(name, node.getNodeValue());
        }
      }
      Node parent = element.getParentNode();
      if (parent instanceof Element) {
        getNamespaceBindings((Element) parent, namespaceMap);
      }
    }
docs: Helper method to {@link #getNamespaceBindings(Element)}
  
  @param element
  the element to parse
  @param namespaceMap
  the map to fill