Here you can find the source of parseXml(String filename, boolean validating)
Parameter | Description |
---|---|
finename | - xml doc file to parse |
validating | - boolean to confirm validation against DTD file |
public static Document parseXml(String filename, boolean validating) throws IOException, ParserConfigurationException, SAXException
//package com.java2s; /*// w ww . j a v a2 s. com ******************************************************************** ** ISFS: NCAR Integrated Surface Flux System software ** ** 2016, Copyright University Corporation for Atmospheric Research ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** The LICENSE.txt file accompanying this software contains ** a copy of the GNU General Public License. If it is not found, ** write to the Free Software Foundation, Inc., ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ** ******************************************************************** */ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; import org.w3c.dom.Document; public class Main { /** Parses an XML file and returns a DOM document. * If validating is true, the contents is validated against the DTD * specified in the file. * @param finename - xml doc file to parse * @param validating - boolean to confirm validation against DTD file */ public static Document parseXml(String filename, boolean validating) throws IOException, ParserConfigurationException, SAXException { return parseXML(new FileInputStream(filename), validating); } /** Parses an XML file and returns a DOM document. * If validating is true, the contents is validated against the DTD * specified in the file. * @param finename - xml doc file to parse * @param validating - boolean to confirm validation against DTD file */ public static Document parseXML(InputStream is, boolean validating) throws IOException, ParserConfigurationException, SAXException { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validating); // Create the builder and parse the file Document doc = factory.newDocumentBuilder().parse(is); return doc; } }