You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Robert Zimmermann <rz...@webde-ag.de> on 2004/03/17 10:23:36 UTC

RE: validating sax parser does not report dtd or wxs errors on t ime

> Hi Robert,
> Xerces does the validation of an element after the element is 
> closed, so 
> that it has a list of child nodes to look at.
> You will always get parsing errors as soon as they are 
> encountered; only 
> validation errors will be reported after the endElement notification.

Oh, I see. And to be honest I did not expect another answer as I was told
Xerces handles this the same way for a long time.

In my case to be sure bad XML does not break the SAX handler code I have to
implement an empty ContentHandler to be run before the real parsing is donne
just to get hold of validation errors.

One could say: well why not do this with DOM? And the answer is: a lot of
SAX handler code would have to be rewritten and this code has evolved for 4
years now.

Anyway, maybe some of the validation code of Xerces could be improved to
report wrong order of child elements before their parent is closed. 
This would reduce a lot of responsibility out of any SAX handler code and I
am not sure if all SAX writers are aware of this as I was not for a long
time.

Thanks for the quick answer Alberto

 Robert

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


SV:RE: validating sax parser does not report dtd or wxs errors on time

Posted by Gröndal Daniel <da...@rfv.sfa.se>.
Hi Robert!

I guess we have exactly the samt problem.

>In my case to be sure bad XML does not break the SAX handler code I have to
>implement an empty ContentHandler to be run before the real parsing is donne
>just to get hold of validation errors.

What I do is that I don't set any contenthandler at all. I parse the file first
with only a errorhandler installed. Then after a successful parse I install the
contenthandler and parse the file again. Time consuming, I know, but I'll do
for now for me. I have to do this since an element and its value can be read
even if that element is not allowed at that level by the dtd and that means
that endElement() might be called for an element which in fact are not allowed
at that specific level.

>
>Anyway, maybe some of the validation code of Xerces could be improved to
>report wrong order of child elements before their parent is closed.
>This would reduce a lot of responsibility out of any SAX handler code and I
>am not sure if all SAX writers are aware of this as I was not for a long
>time.
>

I too considered this, but I don't have time to modify the code right now, so
I'll probably stick to my earlier solution. I was not aware of the fact that
validation errors are reported when an element is closed and it really gave me
some problems.

//daniel


__________________________________________________________
RFV Data/Produktenheten     E-post: daniel.grondal@rfv.sfa.se
Daniel Gröndal              Tfn: 060-187126
S:a Järnvägsgatan 41        Mobil: 070-3016517
851 93 Sundsvall            Fax: 060-147870
__________________________________________________________



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