Java XML Document from Stream getXML(InputStream stream)

Here you can find the source of getXML(InputStream stream)

Description

Reads XML from a stream

License

Open Source License

Parameter

Parameter Description
stream the stream to read the document from

Exception

Parameter Description
IOException , SAXException if an error occurs when reading from the stream

Return

The document

Declaration

public static Document getXML(InputStream stream) throws IOException, SAXException 

Method Source Code

//package com.java2s;
/*/*from ww  w.  jav  a  2  s. c  o  m*/
 * FFNLauncher
 * Copyright (C) 2013 Abel Hoogeveen <http://www.sigmacoders.nl>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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

import java.net.UnknownHostException;

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

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    /**
     * Reads XML from a stream
     * @param stream the stream to read the document from
     * @return The document
     * @return The document
     * @throws IOException, SAXException if an error occurs when reading from the stream
     */
    public static Document getXML(InputStream stream) throws IOException, SAXException {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        try {
            return docFactory.newDocumentBuilder().parse(stream);
        } catch (ParserConfigurationException ignored) {
            System.out.println("getXML parser error v001");
        } catch (UnknownHostException e) {
            System.out.println("getXML UnknowHost error v002");
        }
        return null;
    }
}

Related

  1. getXML(InputStream stream)
  2. load(InputStream data)
  3. load(InputStream inputStream)
  4. load(InputStream stream)