Android XML InputStream Parse parseXml(InputStream is, String elementsTagName)

Here you can find the source of parseXml(InputStream is, String elementsTagName)

Description

parse Xml

Declaration

public static List<String> parseXml(InputStream is,
        String elementsTagName) 

Method Source Code

//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;
    }
}

Related

  1. obtainEncodingStringFromInputStream(InputStream bis)
  2. parse(InputStream in, ContentHandler handler)
  3. parse(InputStream is)
  4. parse(InputStream is)
  5. parse(InputStream is, Class cls, List fields, List elements, String itemelement)