public static Document inputStreamToDocument(InputStream is) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setExpandEntityReferences(false);
        factory.setIgnoringComments(false);
        factory.setIgnoringElementContentWhitespace(false);
        factory.setValidating(false);

        DocumentBuilder builder = factory.newDocumentBuilder();
        Document root = builder.parse(is);

        return root;
    }
public static Document inputStreamToDocument ( InputStream is ) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setExpandEntityReferences ( false ) ; factory . setIgnoringComments ( false ) ; factory . setIgnoringElementContentWhitespace ( false ) ; factory . setValidating ( false ) ; DocumentBuilder builder = factory . newDocumentBuilder ( ) ; Document root = builder . parse ( is ) ; return root ; }
To parse an input stream to DOM
<p/>
This implementation attempts to preserve the xml structure as-is with whitespace etc