Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); you may import java.util.HashMap; import java.util.Map; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Map<String, String> SimpleDocumentToMap(Document doc) { Map<String, String> simpleMap = new HashMap<String, String>(); //trim off outter layer Node node = doc.getFirstChild(); NodeList nList = node.getChildNodes(); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (eElement != null) { simpleMap.put(eElement.getTagName(), eElement.getTextContent()); } // end if eelement } // end if nnode.getnodetype() } //end for int temp return simpleMap; } }