Java XML Document Parse parseDocument(InputStream is)

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

Description

Parses the document.

License

Open Source License

Parameter

Parameter Description
is the is

Exception

Parameter Description
ParserConfigurationException the parser configuration exception
SAXException the sAX exception
IOException Signals that an I/O exception has occurred.

Return

the document

Declaration

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

Method Source Code


//package com.java2s;
/*//from  w  w  w. jav a 2 s. co  m
 * Metadata Editor
 * @author Jiri Kremser
 * 
 * 
 * 
 * Metadata Editor - Rich internet application for editing metadata.
 * Copyright (C) 2011  Jiri Kremser (kremser@mzk.cz)
 * Moravian Library in Brno
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * 
 */

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

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 {
    /**
     * Parses the document.
     * 
     * @param is
     *        the is
     * @return the document
     * @throws ParserConfigurationException
     *         the parser configuration exception
     * @throws SAXException
     *         the sAX exception
     * @throws IOException
     *         Signals that an I/O exception has occurred.
     */
    public static Document parseDocument(InputStream is)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return builder.parse(is);
    }

    /**
     * Parses the document.
     * 
     * @param xml
     *        the xml
     * @return the document
     * @throws ParserConfigurationException
     *         the parser configuration exception
     * @throws SAXException
     *         the sAX exception
     * @throws IOException
     *         Signals that an I/O exception has occurred.
     */
    public static Document parseDocument(String xml)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return builder.parse(new InputSource(new StringReader(xml)));
    }

    public static Document parseDocument(String xml, boolean namespaceaware)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(namespaceaware);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new InputSource(new StringReader(xml)));
    }

    /**
     * Parses the document.
     * 
     * @param is
     *        the is
     * @param namespaceaware
     *        the namespaceaware
     * @return the document
     * @throws ParserConfigurationException
     *         the parser configuration exception
     * @throws SAXException
     *         the sAX exception
     * @throws IOException
     *         Signals that an I/O exception has occurred.
     */
    public static Document parseDocument(InputStream is, boolean namespaceaware)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(namespaceaware);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(is);
    }
}

Related

  1. parseDocument(InputSource is)
  2. parseDocument(InputStream documentXml)
  3. parseDocument(InputStream in)
  4. parseDocument(InputStream is)
  5. parseDocument(InputStream is)
  6. parseDocument(InputStream is)
  7. parseDocument(Path xmlPath)
  8. parseDocument(Reader reader)
  9. parseDocument(String docText)