Java XML Parse File parseXMLFile(File f)

Here you can find the source of parseXMLFile(File f)

Description

This method parses an XML file and returns an org.w3c.dom.Document

License

Open Source License

Parameter

Parameter Description
f a parameter

Declaration

public static Document parseXMLFile(File f) 

Method Source Code

//package com.java2s;
/**/*from   w  w w. j  a v  a 2s  . co m*/
 * XMLUtils.java
 * ----------------------------------------------------------------------------------
 * 
 * Copyright (C) 2008 www.integratedmodelling.org
 * Created: Jan 21, 2008
 *
 * ----------------------------------------------------------------------------------
 * This file is part of ThinklabPersistencePlugin.
 * 
 * ThinklabPersistencePlugin 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.
 * 
 * ThinklabPersistencePlugin 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.
 * 
 * You should have received a copy of the GNU General Public License
 * along with the software; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * ----------------------------------------------------------------------------------
 * 
 * @copyright 2008 www.integratedmodelling.org
 * @author    Ioannis N. Athanasiadis (ioannis@athanasiadis.info)
 * @date      Jan 21, 2008
 * @license   http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 * @link      http://www.integratedmodelling.org
 **/

import java.io.File;

import java.io.IOException;

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

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    /**
     * This method parses an XML file and returns an {@code org.w3c.dom.Document}
     * @param f
     * @return
     */
    public static Document parseXMLFile(File f) {
        Document dom = null;
        //      get the factory
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            //Using factory get an instance of document builder
            DocumentBuilder db = dbf.newDocumentBuilder();
            //parse using builder to get DOM representation of the XML file
            dom = db.parse(f);
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (SAXException se) {
            se.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return dom;
    }
}

Related

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