Here you can find the source of parseXml(InputStream is, String elementsTagName)
public static List<String> parseXml(InputStream is, String elementsTagName)
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class Main { public static List<String> parseXml(InputStream is, String elementsTagName) { List<String> list = new ArrayList<String>(); /* ??XML?????Document???? */ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from www .ja v a2 s . co m DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(is); NodeList nodeList = doc.getElementsByTagName(elementsTagName); int len = nodeList.getLength(); for (int i = 0; i < len; i++) { String content = nodeList.item(i).getChildNodes().item(0) .getNodeValue(); list.add(content); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return list; } }