Java XML Parse Stream parseXML(InputStream in)

Here you can find the source of parseXML(InputStream in)

Description

parse XML document

License

Apache License

Parameter

Parameter Description
in a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static Document parseXML(InputStream in) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    /**//from w  w  w. java  2 s. c o  m
     * parse XML document
     * @param in
     * @return
     * @throws IOException
     */
    public static Document parseXML(InputStream in) throws IOException {
        Document document = null;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //factory.setValidating(true);
        //factory.setNamespaceAware(true);

        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            //builder.setErrorHandler(new XmlErrorHandler());
            //builder.setEntityResolver(new XmlEntityResolver());
            document = builder.parse(in);

            // close input stream
            in.close();
        } catch (Exception ex) {
            throw new IOException(ex.getMessage());
        }
        return document;
    }
}

Related

  1. parseStreamToXML(InputStream in)
  2. parseText(XMLStreamReader parser)
  3. parseValue(XMLStreamReader xmlRdr, String elementName)
  4. parseXml(InputStream in)
  5. parseXml(InputStream in)
  6. parseXml(InputStream inputStream, boolean validating)
  7. parseXML(InputStream is)
  8. parseXML(InputStream is, String[] tagNames)
  9. parseXml(InputStream src)