get XML Attributes Map - Android XML

Android examples for XML:XML Attribute

Description

get XML Attributes Map

Demo Code


//package com.java2s;

import java.util.HashMap;

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

public class Main {
    public static HashMap<String, String> getAttributesMap(Element element) {
        NamedNodeMap attributes = element.getAttributes();
        HashMap<String, String> map = new HashMap<String, String>(
                attributes.getLength());
        for (int i = 0; i < attributes.getLength(); i++) {
            Node item = attributes.item(i);
            map.put(item.getNodeName(), item.getNodeValue());
        }//from  w  w w . j a  v a 2  s  .  com
        return map;
    }
}

Related Tutorials