Here you can find the source of createDocumentFromFile(File file)
public static Document createDocumentFromFile(File file) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; public class Main { public static Document createDocumentFromFile(File file) throws Exception { DocumentBuilderFactory factory = getDocumentBuilderFactory(); DocumentBuilder builder;//from ww w . j av a 2 s. c o m try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new Exception(e); } return builder.parse(file); } private static DocumentBuilderFactory getDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setXIncludeAware(true); return factory; } }