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

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

Description

parse Xml File

License

Open Source License

Declaration

public static Document parseXmlFile(String filename, boolean validating) 

Method Source Code

//package com.java2s;
/**//from   w w  w .j  ava2s  .c  o m
 *     Copyright (C) 2009-2011  Jack A. Rider All rights reserved.
 * 
 *     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 3 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.
 */

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Main {
    public static Document parseXmlFile(String filename, boolean validating) {
        try {
            // Create a builder factory
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(validating);

            // Create the builder and parse the file
            Document doc = factory.newDocumentBuilder().parse(new File(filename));
            return doc;
        } catch (ParserConfigurationException e) {
            System.out.println("-----------------------------------------------");
            System.out.println("Error ParserConfiguration");
            System.out.println("-----------------------------------------------");
        } catch (SAXException e) {
            System.out.println("-----------------------------------------------");
            System.out.println("Error XML input is not valid");
            System.out.println("-----------------------------------------------");
        } catch (IOException e) {
            System.out.println("-----------------------------------------------");
            System.out.println("Error IO exception");
            System.out.println("-----------------------------------------------");
        }
        return null;
    }
}

Related

  1. parseXml(String value, boolean isFile)
  2. parseXMLFile(File f)
  3. parseXmlFile(File file)
  4. parseXmlFile(File file, boolean validating)
  5. parseXMLFile(final File xmlFile)
  6. parseXmlFile(String in)
  7. parseXmlFile(String xml)
  8. parseXmlFile(String xmlFile)
  9. parseXmlFile(String xmlFile)