You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by 周平 <zh...@sinosoft.com.cn> on 2008/11/17 13:39:36 UTC

which xml parse package that ant use?

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?


Re: which xml parse package that ant use?

Posted by Peter Reilly <pe...@gmail.com>.
Also sax is stream based - so the first errors  that
ant would see would be the fact that the first element is
not "project"  the malformed xml document would
not be noticed at this stage as processing of the
document would stop.

Peter


On Mon, Nov 17, 2008 at 3:46 PM, Stefan Bodewig <bo...@apache.org> wrote:
> Ant uses a SAX parser, not a DocumentBuilder (see
> javax.xml.parsers,SAXParser), this alone may explain the difference.
>
> It will use whatever JAXP provides, but Ant ships with a pretty recent
> version of Apache Xerces.
>
> Finally, the error message you cite comes from Ant, not the parser.
> If the documents wasn't at least well-formed, Ant wouldn't get a
> chance to say which element was different from the one it expected.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: which xml parse package that ant use?

Posted by Stefan Bodewig <bo...@apache.org>.
Ant uses a SAX parser, not a DocumentBuilder (see
javax.xml.parsers,SAXParser), this alone may explain the difference.

It will use whatever JAXP provides, but Ant ships with a pretty recent
version of Apache Xerces.

Finally, the error message you cite comes from Ant, not the parser.
If the documents wasn't at least well-formed, Ant wouldn't get a
chance to say which element was different from the one it expected.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org