Here you can find the source of parseXmlFile(String filename, boolean validating)
public static Document parseXmlFile(String filename, boolean validating)
//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; } }