Here you can find the source of parseXml(InputStream inputStream, boolean validating)
Parameter | Description |
---|---|
inputStream | a parameter |
validating | a parameter |
Parameter | Description |
---|---|
ParserConfigurationException | an exception |
IOException | an exception |
SAXException | an exception |
public static Document parseXml(InputStream inputStream, boolean validating) throws DOMException, ParserConfigurationException, SAXException, IOException
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static DocumentBuilder domBuilder = null; /**/* w w w.j a v a2s . c o m*/ * Parses an XML input stream and returns a DOM document. If validating is true, the contents is validated against the DTD specified in * the file. * * @param inputStream * @param validating * @return * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public static Document parseXml(InputStream inputStream, boolean validating) throws DOMException, ParserConfigurationException, SAXException, IOException { if (domBuilder == null) { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validating); // Configure it to ignore comments factory.setIgnoringComments(true); // check namespace factory.setNamespaceAware(true); // Create the builder and parse the file domBuilder = factory.newDocumentBuilder(); // if (!domBuilder.getDOMImplementation().hasFeature("traversal", "2.0")) { // supportTraversal = false; // } } Document doc = domBuilder.parse(inputStream); // do the normalization doc.normalize(); return doc; } public static Document parseXml(String xmlContent, boolean validating) throws DOMException, ParserConfigurationException, SAXException, IOException { ByteArrayInputStream bis = new ByteArrayInputStream(xmlContent.getBytes()); return parseXml(bis, validating); } }