Java XML Document from Stream readXML(InputStream is)

Here you can find the source of readXML(InputStream is)

Description

Read input stream into XML Document element

License

LGPL

Parameter

Parameter Description
is a parameter

Exception

Parameter Description
ParserConfigurationException an exception
SAXException an exception
IOException an exception

Declaration

public static Document readXML(InputStream is) throws ParserConfigurationException, SAXException, IOException 

Method Source Code

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

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

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    /**/*from   ww w. jav a  2 s  . c  om*/
     * Read input stream into XML Document element
     * 
     * @param is
     * @return
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     */
    public static Document readXML(InputStream is) throws ParserConfigurationException, SAXException, IOException {
        javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);

        javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();

        org.w3c.dom.Document doc = db.parse(is);

        return doc;
    }

    /**
     * Read a XML text file to XML Document object
     *  
     * @param xmlFile
     * @return
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     */
    public static Document readXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException {
        javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);

        javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();

        org.w3c.dom.Document doc = db.parse(xmlFile);

        return doc;
    }
}

Related

  1. loadXmlFromInputSource(InputSource is)
  2. readXML(InputStream input)
  3. readXml(InputStream inputStream)
  4. readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error)
  5. readXML(InputStream inStream)