Java tutorial
//package com.java2s; 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 DocumentBuilder docBuilder; public static Document getXMLDocument(String path) throws SAXException, IOException, ParserConfigurationException { Document d = getDocumentBuilder().parse(new File(path)); d.getDocumentElement().normalize(); doneParsing(); return d; } private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { if (docBuilder == null) { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } else { docBuilder.reset(); } return docBuilder; } public static void doneParsing() { docBuilder = null; } }