I find that Ant will output detail error information when a ill-form build.xml is presented, even when build.xml isn’t a valid xml file. But when I use other package to parse XML files, I can’t get detail error message just like which Ant generate. Following is a test file, which contains only three lines.
<head> <body></body> <!-- </head> --> Obviously, it isn’t a valid xml file. Codes to parse this file shows below DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; Document doc = null; try { db = dbf.newDocumentBuilder(); doc = db.parse(new FileInputStream("D:/work/jbs/src/build.xml")); doc.getDocumentElement(); } catch (Exception ex) { ex.printStackTrace(); } output is [Fatal Error] :3:1: XML document structures must start and end within the same entity. But what ant shows in console is D:\work\jbs\src\build.xml:1: Unexpected element "{}head" {antlib:org.apache. tools.ant}head The difference is that ant can show you the exact element which contains error. It has great help to users especially when they handle big xml files. Anyone know which package that ant use to parse xml files?