parse XML from InputStream into DOM Document - Java XML

Java examples for XML:DOM

Description

parse XML from InputStream into DOM Document

Demo Code


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

public class Main {
    public static Document parseXML(InputStream stream) throws Exception {
        DocumentBuilderFactory objDocumentBuilderFactory = null;
        DocumentBuilder objDocumentBuilder = null;
        Document doc = null;/* w  ww.j  av a2s.  c  o  m*/
        try {
            objDocumentBuilderFactory = DocumentBuilderFactory
                    .newInstance();
            objDocumentBuilder = objDocumentBuilderFactory
                    .newDocumentBuilder();

            doc = objDocumentBuilder.parse(stream);
        } catch (Exception ex) {
            throw ex;
        }

        return doc;
    }
}

Related Tutorials