Java XML Document Create getDocument(File file)

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

Description

get Document

License

Open Source License

Declaration

public static Document getDocument(File file) 

Method Source Code


//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2011 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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

public class Main {
    public static Document getDocument(File file) {
        try {/*ww w  .j  av a  2  s. com*/
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            return db.parse(file);
        } catch (Exception ex) {
            return null;
        }
    }

    public static Document getDocument() {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            return db.newDocument();
        } catch (Exception ex) {
            return null;
        }
    }
}

Related

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