Here you can find the source of getXmlDocument(File file)
private static Document getXmlDocument(File file)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static Document getXmlDocument(File file) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try {/* w ww .j a va 2s. c om*/ docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(file); return doc; } catch (ParserConfigurationException e) { return null; } catch (SAXException e) { return null; } catch (IOException e) { return null; } } }