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

Java examples for XML:DOM

Description

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

Demo Code


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

public class Main {
    /**/*from w w  w  .  j a va2  s .c o m*/
     * 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 Tutorials