Java tutorial
//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 getDocumentFromStream(InputStream is, boolean namespaceAware) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(namespaceAware); DocumentBuilder builder = dbf.newDocumentBuilder(); Document ret = builder.parse(is); return ret; } catch (Exception e) { throw new RuntimeException(e); } } }