Java XML Document from File getXmlDocument(String fileName)

Here you can find the source of getXmlDocument(String fileName)

Description

getXmlDocoument retrieve w3c.Document from given file

License

Educational Community License

Parameter

Parameter Description
fileName a parameter

Exception

Parameter Description
Exception an exception

Return

Document

Declaration

public static Document getXmlDocument(String fileName) throws Exception 

Method Source Code

//package com.java2s;
/**/*from www.j  av a2  s  .  co m*/
 *  This document is a part of the source code and related artifacts
 *  for CollectionSpace, an open source collections management system
 *  for museums and related institutions:

 *  http://www.collectionspace.org
 *  http://wiki.collectionspace.org

 *  Copyright 2009 University of California at Berkeley

 *  Licensed under the Educational Community License (ECL), Version 2.0.
 *  You may not use this file except in compliance with this License.

 *  You may obtain a copy of the ECL 2.0 License at

 *  https://source.collectionspace.org/collection-space/LICENSE.txt

 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.File;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    /**
     * getXmlDocoument retrieve w3c.Document from given file
     * 
     * @param fileName
     * @return Document
     * @throws Exception
     */
    public static Document getXmlDocument(String fileName) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();
        File f = new File(fileName);
        if (!f.exists()) {
            throw new IllegalArgumentException("Test data file " + fileName
                    + " not found!");
        }
        // Create the builder and parse the file
        return factory.newDocumentBuilder().parse(f);
    }
}

Related

  1. getDocumentFromFile(String absolutePath)
  2. getXML(File file)
  3. getXML(File xmlFile)
  4. getXmlDocument(File file)
  5. getXmlDocument(File file)
  6. isXMLFile(File file)
  7. load(String file)
  8. load(String sFileName)
  9. loadDocument(File documentFile)