code: public static void copyAttributes(Element source, Map<String, String> dest) {
          NamedNodeMap attributes = source.getAttributes();
  
          if (attributes != null) {
              for (int i = 0; i < attributes.getLength(); i++) {
                  Node attribute = attributes.item(i);
                  dest.put(attribute.getNodeName(), attribute.getNodeValue());
              }
          }
      }
docs: Copy attributes from a DOM node to a map.
  
  @param source DOM node.
  @param dest Destination map.