Java XML Document from File readXMLFile(File file)

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

Description

read XML File

License

Open Source License

Declaration

public static Document readXMLFile(File file) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2010 Oracle//from   ww  w. j a v a  2 s  .co m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Original file was copied from
 * org.eclipse.wst.common.project.facet.core.util.internal.FileUtil
 *
 ******************************************************************************/

import java.io.File;

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

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

public class Main {
    public static Document readXMLFile(File file) {
        return readXMLFile(file, null);
    }

    public static Document readXMLFile(File file, EntityResolver resolver) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db;

        try {
            db = dbf.newDocumentBuilder();

            if (resolver != null) {
                db.setEntityResolver(resolver);
            }

            return db.parse(file);
        } catch (Throwable SWTBot) {
            return null;
        }
    }
}

Related

  1. readXML(File file)
  2. readXML(File file)
  3. readXML(File xml)
  4. readXml(String path)
  5. readXML(String path)
  6. readXMLFile(String filename)
  7. readXmlFile(String fileName)
  8. readXmlFile(String fileName)
  9. readXMLFile(String filename)