Here you can find the source of getDocument(File file)
public static Document getDocument(File file)
//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; } } }