Here you can find the source of parseDocument(InputStream is)
Parameter | Description |
---|---|
is | an input stream |
public static Document parseDocument(InputStream is)
//package com.java2s; import java.io.InputStream; import org.w3c.dom.DOMConfiguration; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.bootstrap.DOMImplementationRegistry; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSParser; public class Main { private static DOMImplementation impl; private static DOMImplementationRegistry registry; /**//from w w w . j a v a 2 s . c o m * Parses the given input stream as XML and returns the corresponding DOM * document. * * @param is * an input stream * @return a DOM document if something goes wrong */ public static Document parseDocument(InputStream is) { getImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) impl; // serialize to XML LSInput input = implLS.createLSInput(); input.setByteStream(is); // parse without comments and whitespace LSParser builder = implLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); DOMConfiguration config = builder.getDomConfig(); config.setParameter("comments", false); config.setParameter("element-content-whitespace", false); return builder.parse(input); } /** * Creates a new instance of the DOM registry and get an implementation of * DOM 3 with Load Save objects. * */ private static void getImplementation() { if (registry == null) { try { registry = DOMImplementationRegistry.newInstance(); } catch (ClassCastException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } if (impl == null) { impl = registry.getDOMImplementation("Core 3.0 XML 3.0 LS"); } } }