Java XML Parse Stream parse(final InputStream in)

Here you can find the source of parse(final InputStream in)

Description

Parse an XML document.

License

Open Source License

Parameter

Parameter Description
in The input stream.

Exception

Parameter Description
SAXException If there is a parsing error.
IOException If there is an I/O error.
IllegalArgumentException If there is a parser configuration error.

Return

A Document.

Declaration

public static Document parse(final InputStream in) throws SAXException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    /**/*w  w w.jav  a  2s .c om*/
     * Parse an XML document.
     *
     * @param in
     *            The input stream.
     *
     * @return A Document.
     *
     * @throws SAXException
     *             If there is a parsing error.
     * @throws IOException
     *             If there is an I/O error.
     * @throws IllegalArgumentException
     *             If there is a parser configuration error.
     */
    public static Document parse(final InputStream in) throws SAXException, IOException {
        return parse(new InputSource(in));
    }

    /**
     * Parse an XML document.
     *
     * @param is
     *            The input source.
     *
     * @return A Document.
     *
     * @throws SAXException
     *             If there is a parsing error.
     * @throws IOException
     *             If there is an I/O error.
     * @throws IllegalArgumentException
     *             If there is a parser configuration error.
     */
    public static Document parse(final InputSource is) throws SAXException, IOException {
        try {
            final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

            return builder.parse(is);
        } catch (final ParserConfigurationException ex) {
            throw new IllegalArgumentException("DOM parser configuration error: " + ex.getMessage());
        }
    }
}

Related

  1. getNextStartElement(XMLStreamReader parser)
  2. getParamStream(XMLOutputFactory outputFactory, XMLEventFactory eventFactory, XMLEventReader parser, XMLEvent paramEvent)
  3. parse(DefaultHandler handler, InputStream in)
  4. parse(final InputStream inputStream)
  5. parse(final InputStream is)
  6. parse(InputStream anInputStream)
  7. parse(InputStream byteStream)