Java XML Document Create getDocument(File file)

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

Description

Parses an XML file.

License

Open Source License

Parameter

Parameter Description
file the file containing the XML to parse.

Return

the XML DOM document.

Declaration

public static Document getDocument(File file) throws Exception 

Method Source Code


//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2005 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

import java.io.*;

import org.w3c.dom.Document;

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

public class Main {
    /**/*  w  w w  .  j  av a 2  s . c o m*/
     * Parses an XML file.
     * @param realFilePath the path to the file containing the XML to parse.
     * @return the XML DOM document.
     */
    public static Document getDocument(String realFilePath) throws Exception {
        File file = new File(realFilePath);
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return db.parse(file);
    }

    /**
     * Parses an XML file.
     * @param file the file containing the XML to parse.
     * @return the XML DOM document.
     */
    public static Document getDocument(File file) throws Exception {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return db.parse(file);
    }

    /**
     * Creates a new empty XML DOM document.
     * @return the XML DOM document.
     */
    public static Document getDocument() throws Exception {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return db.newDocument();
    }
}

Related

  1. getDocument()
  2. getDocument()
  3. getDocument(Document document)
  4. getDocument(DOMSource source)
  5. getDocument(File f)
  6. getDocument(File file)
  7. getDocument(File file)
  8. getDocument(File file)
  9. getDocument(File file)