Here you can find the source of parse(InputStream byteStream)
Parameter | Description |
---|---|
byteStream | The input stream. |
public static Document parse(InputStream byteStream)
//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 { /**/*from w ww. j a va2 s . co m*/ * Parses the input stream and returns a DOM {@link Document}. * * @param byteStream * The input stream. * @return The {@link Document} parsed from the input. */ public static Document parse(InputStream byteStream) { // input DOMImplementationLS impl = (DOMImplementationLS) getDOMImplementation(); LSInput input = impl.createLSInput(); input.setByteStream(byteStream); // parse without comments and whitespace LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); DOMConfiguration config = builder.getDomConfig(); config.setParameter("comments", false); config.setParameter("element-content-whitespace", false); // returns the document parsed from the input return builder.parse(input); } /** * Returns a DOM implementation that has the following features: * <ul> * <li>Core 3.0</li> * <li>XML 3.0</li> * <li>LS</li> * </ul> * * @return A {@link DOMImplementation} object that can be cast to * {@link DOMImplementationLS}. */ public static DOMImplementation getDOMImplementation() { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); return registry.getDOMImplementation("Core 3.0 XML 3.0 LS"); } catch (Exception e) { throw new RuntimeException(e); } } }