Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { public static Document getXmlDocument(String filePath) throws Exception { return getXmlDocument(new File(filePath)); } public static Document getXmlDocument(File file) throws Exception { DocumentBuilderFactory docBuilderFactory = null; DocumentBuilder db = null; Document document = null; docBuilderFactory = DocumentBuilderFactory.newInstance(); db = docBuilderFactory.newDocumentBuilder(); if (file.exists()) { FileInputStream in = new FileInputStream(file); document = db.parse(in); in.close(); } db = null; docBuilderFactory = null; return document; } }