Java XML Document from File getXmlDocument(File file)

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

Description

Gets Document representation of xml file

License

Open Source License

Parameter

Parameter Description
file xml file

Return

Document object

Declaration

public static Document getXmlDocument(File file) 

Method Source Code


//package com.java2s;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    /**/*from  www  . ja v a2s.c  om*/
     * Gets Document representation of xml file
     * 
     * @param file
     *            xml file
     * @return Document object
     */
    public static Document getXmlDocument(File file) {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(file);
            return doc;
        } catch (Exception e) {
            throw new RuntimeException("Could not parse XML document", e);
        }
    }
}

Related

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