Java tutorial
//package com.java2s; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilderFactory; import java.io.*; public class Main { public static Document file2Document(File file) throws Exception { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must exist![" + file == null ? "NULL" : ("Could not be found: " + file.getAbsolutePath()) + "]"); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); return dbFactory.newDocumentBuilder().parse(new FileInputStream(file)); } }