Java tutorial
//package com.java2s; import java.util.*; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static HashMap<String, String> getEleAttrNameValueMap(Element ele) { HashMap<String, String> ht = new HashMap<String, String>(); NamedNodeMap nnm = ele.getAttributes(); int len = nnm.getLength(); Node tmpn = null; for (int k = 0; k < len; k++) { tmpn = nnm.item(k); String tmps = tmpn.getNodeValue(); if (tmps == null) { tmps = ""; } ht.put(tmpn.getNodeName(), tmps); } return ht; } }