Here you can find the source of parser(InputStream inputStream)
public static Map<String, String> parser(InputStream inputStream)
//package com.java2s; //License from project: Apache License import java.io.InputStream; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class Main { public static Map<String, String> parser(InputStream inputStream) { Map<String, String> xmlMap = new HashMap<String, String>(); try {//from ww w. java2s. c om DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(inputStream); Element root = document.getDocumentElement(); NodeList nodes = root.getChildNodes(); int len = nodes.getLength(); for (int i = 0; i < len; i++) { Node node = nodes.item(i); xmlMap.put(node.getNodeName(), node.getTextContent()); } } catch (Exception e) { e.printStackTrace(); } return xmlMap; } public static Map<String, String> parser(String xmlStr) { Map<String, String> xmlMap = new HashMap<String, String>(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xmlStr)); Document document = db.parse(is); Element root = document.getDocumentElement(); NodeList nodes = root.getChildNodes(); int len = nodes.getLength(); for (int i = 0; i < len; i++) { Node node = nodes.item(i); xmlMap.put(node.getNodeName(), node.getTextContent()); } } catch (Exception e) { e.printStackTrace(); } return xmlMap; } }