Java XML Parse File parse(File file)

Here you can find the source of parse(File file)

Description

parse

License

Open Source License

Declaration

public static Document parse(File file)
            throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError 

Method Source Code


//package com.java2s;
/* /*from  w ww  . j  a va2s  .  c o  m*/
* This file is part of DISMOD Core. 
* ? Copyright 2003-2011 Fraunhofer Institut f. Materialfluss und Logistik.
* http://www.iml.fraunhofer.de, http://www.verkehrslogistik.de
*
* DISMOD Core is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* DISMOD Core 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 Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with DISMOD Core.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

import java.net.URL;

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

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    public static Document parse(File file)
            throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError {
        FileInputStream in = new FileInputStream(file);
        Document out = parse(in);
        in.close();
        return out;
    }

    public static Document parse(URL url)
            throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError {
        InputStream in = url.openStream();
        Document out = parse(in);
        in.close();
        return out;
    }

    public static Document parse(InputStream in)
            throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(in);
        return document;
    }
}

Related

  1. parse(File f)
  2. parse(File f)
  3. parse(File f, boolean validation)
  4. parse(File f, DefaultHandler dh)
  5. parse(File file)
  6. parse(File file)
  7. parse(File file)
  8. parse(File file)
  9. parse(File file)