Java XML Document from Stream loadDocument(InputStream documentInputStream)

Here you can find the source of loadDocument(InputStream documentInputStream)

Description

Loads a DOM document from the given input stream.

License

Open Source License

Exception

Parameter Description
SAXException an exception
IOException an exception

Declaration

public static Document loadDocument(InputStream documentInputStream) throws SAXException, IOException 

Method Source Code


//package com.java2s;
/*//from   w ww .  j  a va 2 s  . c  om
 * SafeOnline project.
 *
 * Copyright 2006-2007 Lin.k N.V. All rights reserved.
 * Lin.k N.V. proprietary/confidential. Use is subject to license terms.
 */

import java.io.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    /**
     * Loads a DOM document from the given input stream.
     *
     * @throws SAXException
     * @throws IOException
     */
    public static Document loadDocument(InputStream documentInputStream) throws SAXException, IOException {

        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);

            return documentBuilderFactory.newDocumentBuilder().parse(documentInputStream);
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getXML(InputStream stream)
  2. load(InputStream data)
  3. load(InputStream inputStream)
  4. load(InputStream stream)
  5. loadDocument(InputStream documentInputStream)
  6. loadDocument(InputStream in)
  7. loadDocument(InputStream is)
  8. loadDocument(InputStream is)
  9. loadXmlDocumentFromStream(@Nonnull InputStream in)