convert Xml Attribute To Hash Map - Android XML

Android examples for XML:XML Attribute

Description

convert Xml Attribute To Hash Map

Demo Code


//package com.java2s;

import java.util.HashMap;

import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;

public class Main {
    public static HashMap<String, String> convertXmlAttributeToHashMap(
            NamedNodeMap inputNodeMap) {
        HashMap<String, String> outputHashMap = new HashMap<String, String>();

        for (int i = 0; i < inputNodeMap.getLength(); i++) {
            Attr inputNodeMapAttribute = (Attr) inputNodeMap.item(i);
            outputHashMap.put(inputNodeMapAttribute.getName().trim(),
                    inputNodeMapAttribute.getValue().trim());
        }/*from ww  w.j a va2s.c o m*/

        return outputHashMap;
    }
}

Related Tutorials