Java XML Document from Stream loadXMLFrom(final InputStream is)

Here you can find the source of loadXMLFrom(final InputStream is)

Description

Loads an XML document from the input stream into a DOM Document.

License

Open Source License

Parameter

Parameter Description
is the input stream to load from

Exception

Parameter Description
SAXException if a SAX parsing error occurs
IOExceptionif an IO error occurs
ParserConfigurationException if a JAXP configuration parsingerror occurs

Return

the new Document

Declaration

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

Method Source Code

//package com.java2s;
/**/* w  ww .j ava 2 s  .  co m*/
 * This file is part of the au-xml-util package
 *
 * Copyright Trenton D. Adams <trenton daught d daught adams at gmail daught ca>
 * 
 * au-xml-util is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * au-xml-util is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with au-xml-util.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * See the COPYING file for more information.
 */

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.io.*;

public class Main {
    /**
     * Loads an XML document from the input stream into a DOM Document.
     *
     * @param is the input stream to load from
     *
     * @return the new Document
     *
     * @throws SAXException                 if a SAX parsing error occurs
     * @throws IOException                  if an IO error occurs
     * @throws ParserConfigurationException if a JAXP configuration parsing
     *                                      error occurs
     */
    public static Document loadXMLFrom(final InputStream is)
            throws SAXException, IOException, ParserConfigurationException {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = null;
        builder = factory.newDocumentBuilder();
        assert builder != null;
        final Document doc = builder.parse(is);
        is.close();
        return doc;
    }

    public static Document loadXMLFrom(final InputSource is)
            throws ParserConfigurationException, IOException, SAXException {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = null;
        builder = factory.newDocumentBuilder();
        assert builder != null;
        final Document doc = builder.parse(is);
        return doc;
    }
}

Related

  1. loadDocument(InputStream documentInputStream)
  2. loadDocument(InputStream in)
  3. loadDocument(InputStream is)
  4. loadDocument(InputStream is)
  5. loadXmlDocumentFromStream(@Nonnull InputStream in)
  6. loadXmlFromInputSource(InputSource is)
  7. readXML(InputStream input)
  8. readXml(InputStream inputStream)
  9. readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error)