Here you can find the source of parseMulXML( InputStream is, String[] tagNames)
public static ArrayList<HashMap<String, String>> parseMulXML( InputStream is, String[] tagNames)
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; 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; public class Main { private static DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance();/* ww w .j a va2s . c o m*/ public static ArrayList<HashMap<String, String>> parseMulXML( InputStream is, String[] tagNames) { ArrayList<HashMap<String, String>> returnValues = new ArrayList<HashMap<String, String>>(); try { DocumentBuilder docBuilder = factory.newDocumentBuilder(); Document doc = docBuilder.parse(is); Element rootElement = doc.getDocumentElement(); for (int i = 0; i < tagNames.length; i++) { NodeList targetNodes = rootElement .getElementsByTagName(tagNames[i]); if (targetNodes.getLength() <= 0) { System.out.println("no " + tagNames[i] + " tag in XML response...returning null"); } else { for (int j = 0; j < targetNodes.getLength(); j++) { HashMap<String, String> valueList = new HashMap<String, String>(); Node node = targetNodes.item(j); //parse child nodes NodeList child = node.getChildNodes(); for (int c = 0; c < node.getChildNodes() .getLength(); c++) { child.item(c).getNodeName(); valueList.put(child.item(c).getNodeName(), child.item(c).getTextContent()); } returnValues.add(valueList); } } } } catch (Exception ex) { System.out.println(ex); } return returnValues; } }