Java XML Parse File parseXml(String filename, boolean validating)

Here you can find the source of parseXml(String filename, boolean validating)

Description

Parses an XML file and returns a DOM document.

License

Open Source License

Parameter

Parameter Description
finename - xml doc file to parse
validating - boolean to confirm validation against DTD file

Declaration

public static Document parseXml(String filename, boolean validating)
        throws IOException, ParserConfigurationException, SAXException 

Method Source Code

//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;
    }
}

Related

  1. parseXml(File file)
  2. parseXml(File file)
  3. parseXml(File file)
  4. parseXML(final File file)
  5. parseXml(String fileName)
  6. parseXml(String filePath)
  7. parseXml(String filePath)
  8. parseXml(String value, boolean isFile)
  9. parseXMLFile(File f)