Java XML Attribute Get getAttributesAsMap(Element e)

Here you can find the source of getAttributesAsMap(Element e)

Description

Return the attributes from the specified element as a Map

License

Open Source License

Declaration

public static Map<String, String> getAttributesAsMap(Element e) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.util.HashMap;

import java.util.Map;

import org.w3c.dom.Attr;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /** Return the attributes from the specified element as a Map */
    public static Map<String, String> getAttributesAsMap(Element e) {
        Map<String, String> result = new HashMap<String, String>();
        NamedNodeMap attrs = e.getAttributes();
        if (attrs != null) {
            int len = attrs.getLength();
            for (int i = 0; i < len; i++) {
                Node n = attrs.item(i);
                if (n instanceof Attr) {
                    Attr a = (Attr) n;
                    result.put(a.getName(), a.getValue());
                }/*from w w  w .j  a  v  a 2  s .c o  m*/
            }
        }
        return result;
    }
}

Related

  1. getAttributes(Node node)
  2. getAttributes(Node node)
  3. getAttributes(Node node)
  4. getAttributes(String element, String xsd)
  5. getAttributes(XMLEvent evt)
  6. getAttributesByName(Node node, ArrayList attrNames)
  7. getAttributesCompact(NamedNodeMap attributes)
  8. getAttributesNamesOf(Element element)
  9. getAttributeString(Node node, String name)