Android Utililty Methods XML InputStream Parse

List of utility methods to do XML InputStream Parse

Description

The list of methods to do XML InputStream Parse are organized into topic(s).

Method

DocumentInputStreamToDocument(InputStream istr)
Input Stream To Document
DocumentBuilderFactory dFactory = DocumentBuilderFactory
        .newInstance();
dFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
Document xml = dBuilder.parse(istr);
return xml;
DocumentLoadXml(InputStream stream)
Load Xml
DocumentBuilderFactory factory = DocumentBuilderFactory
        .newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(stream);
return doc;
DocumentgetDocument(InputStream is)
get Document
DocumentBuilderFactory domfactory = DocumentBuilderFactory
        .newInstance();
domfactory.setNamespaceAware(true); 
DocumentBuilder builder = domfactory.newDocumentBuilder();
Document doc = builder.parse(is);
return doc;
XmlPullParsergetPullParser(InputStream in, String encoding)
get Pull Parser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser pullParser = null;
pullParser = factory.newPullParser();
pullParser.setInput(in, encoding);
return pullParser;
XmlPullParsernewPullParser(InputStream input)
Create the factory if necessary and return a new pull parser.
if (sFactory == null) {
    sFactory = XmlPullParserFactory.newInstance();
final XmlPullParser parser = sFactory.newPullParser();
parser.setInput(input, null);
return parser;
StringobtainEncodingStringFromInputStream(InputStream bis)
Helper method to obtain the content encoding from an input stream.
String encoding = "UTF-8";
if (!bis.markSupported()) {
    throw new IllegalArgumentException(
            "Error in the program, InputStream needs to support markSupported()");
bis.mark(ENOUGH);
DataInputStream dis = new DataInputStream(bis);
String line = dis.readLine();
...
XMLReaderparse(InputStream in, ContentHandler handler)
parse
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(handler);
reader.parse(new InputSource(in));
in.close();
return reader;
Documentparse(InputStream is)
This will parse an XML stream and create a DOM document.
try {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
            .newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    return builder.parse(is);
} catch (Exception e) {
    IOException thrown = new IOException(e.getMessage());
    throw thrown;
...
Documentparse(InputStream is)
This will parse an XML stream and create a DOM document.
try {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
            .newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    return builder.parse(is);
} catch (FactoryConfigurationError e) {
    throw new IOException(e.getMessage(), e);
} catch (ParserConfigurationException e) {
...
ArrayListparse(InputStream is, Class cls, List fields, List elements, String itemelement)
parse
ArrayList<Object> result = new ArrayList<Object>();
try {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(is, "UTF-8");
    int event_type = parser.getEventType();
    Object obj = null;
    String name = "";
    while (event_type != XmlPullParser.END_DOCUMENT) {
...