Java XML Parse Stream parse(InputStream is)

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

Description

This will parse an XML stream and create a DOM document.

License

Open Source License

Parameter

Parameter Description
is The stream to get the XML from.

Exception

Parameter Description
IOException It there is an error creating the dom.

Return

The DOM document.

Declaration

public static Document parse(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
import java.io.InputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

public class Main {
    /**//from  w ww.j av a  2 s .c om
     * This will parse an XML stream and create a DOM document.
     * 
     * @param is The stream to get the XML from.
     * @return The DOM document.
     * @throws IOException It there is an error creating the dom.
     */
    public static Document parse(InputStream is) throws IOException {
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            return builder.parse(is);
        } catch (Exception e) {
            IOException thrown = new IOException(e.getMessage());
            throw thrown;
        }
    }
}

Related

  1. parse(InputStream inputStream)
  2. parse(InputStream is)
  3. parse(InputStream is)
  4. parse(InputStream is)
  5. parse(InputStream is)
  6. parse(InputStream is)
  7. parse(InputStream s, boolean validateIfSchema)
  8. parse(InputStream stream)
  9. parse(XMLStreamReader reader)