Here you can find the source of readXMLFile(String filename)
public static Node readXMLFile(String filename) throws Exception
//package com.java2s; import org.w3c.dom.Node; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.xml.sax.SAXParseException; import org.w3c.dom.Document; import java.io.File; public class Main { /**//from ww w.j a v a 2s. c om Reads an XML document and returns the root node (which is all you need 99% of the time) */ public static Node readXMLFile(String filename) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = null; // simplify exceptions because we are only interested in parsing // errors. try { document = builder.parse(new File(filename)); } catch (SAXParseException spe) { String errtxt = "parse error in " + spe.getSystemId() + ",\nline: " + spe.getLineNumber() + " " + spe.getMessage(); throw new IllegalArgumentException(errtxt); } return document.getDocumentElement(); } }