You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by kh...@zycus.com on 2005/11/23 11:38:15 UTC

XML SAX well-formedness Error Reporting.

Hi,

We are developing an module which reads data from XML File & we are using
SAX Parser for parsing.
Below is the pseudo code for the same:

      XMLReader xmlReader = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser" );
      xmlReader = XMLReaderFactory.createXMLReader();
      SAXXMLHanlder handler = new SAXXMLHanlder();

      xmlReader.setContentHandler(handler);
      xmlReader.setFeature("http://xml.org/sax/features/validation",true);
      SAXXMLValidator errorHandler = new SAXXMLValidator();
      xmlReader.setErrorHandler(errorHandler);
      xmlReader.parse(...);

We also have SAXXMLValidator Class implementing ErrorHandler, which just
prints error messages to Logs.

The issue is, when the XML Document is malformed, errors are reported in
the logs and the execution proceeds ahead. There is no Exception thrown out
for any well-formedness error.

Is this the usual behavior? Or are we missing anything out, as we want the
processing to halt if XML is not well-formed.

Any ideas in this regards would be highly appreciated.

Thanks,
Khyati

Khyati Rana
Software Engineer
Zycus, Inc.
Spend Data Management Solutions
Save Whenever you Spend

Tel. - +91-22-56407676  Ext – 7625
Fax - +91-22-26850580
khyati@zycus.com

Your only obligation in any lifetime is to be true to " yourself ".  -
Richard Bach

~~~~~~~~~~~Disclaimer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This e-mail contains confidential information and may be legally
privileged. It is intended solely for the addressee. Access to this email
by anyone else is unauthorized. If you are not the intended addressee,
please inform the sender immediately, delete the e-mail and do not copy,
disseminate, distribute, store, print or deliver this e-mail or information
therein to anybody. The sender and the Company are not liable for any
errors or omissions in this e-mail or for any claims, losses, damages
arising out of this e-mail and information contained therein.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: XML SAX well-formedness Error Reporting.

Posted by kh...@zycus.com.
Hi,

Yes you are right, as am new to XML, I realized that there is a confusion
between Validity Errors and well-formedness Errors.
For Validation Errors no Exception was thrown out by our ErrorHandler
Implementation, and hence the parsing continued.
Only for Fatal Errors i.e. well-formedness Errors it used to stop parsing.

Now we rethrow the Exception for Validity Errors, hence the parsing halts.

Thank you very much for the reply !

Thanks,
Khyati







                                                                           
             Elliotte Harold                                               
             <elharo@metalab.u                                             
             nc.edu>                                                    To 
                                       j-users@xerces.apache.org           
             11/23/2005 09:18                                           cc 
             PM                                                            
                                                                   Subject 
                                       Re: XML SAX well-formedness Error   
             Please respond to         Reporting.                          
             j-users@xerces.ap                                             
                 ache.org                                                  
                                                                           
                                                                           
                                                                           
                                                                           




khyati@zycus.com wrote:

> We also have SAXXMLValidator Class implementing ErrorHandler, which just
> prints error messages to Logs.
>
> The issue is, when the XML Document is malformed, errors are reported in
> the logs and the execution proceeds ahead. There is no Exception thrown
out
> for any well-formedness error.

That's very strange and shouldn't happen. Does parsing continue, or does
parsing stop with no exception? Are you sure you aren't confusing
well-formedness and validity errors? They aren't the same, and don't
have the same effect.

If nothing else, you could always just rethrow the exception from your
error handler. You have to do this for validity errors. I don't think
you should have to do it for well-formedness errors though, but maybe
that's changed. Do you have a reproducible test case?

-- Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


ForwardSourceID:NT000154BA


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: XML SAX well-formedness Error Reporting.

Posted by Elliotte Harold <el...@metalab.unc.edu>.
khyati@zycus.com wrote:

> We also have SAXXMLValidator Class implementing ErrorHandler, which just
> prints error messages to Logs.
> 
> The issue is, when the XML Document is malformed, errors are reported in
> the logs and the execution proceeds ahead. There is no Exception thrown out
> for any well-formedness error.

That's very strange and shouldn't happen. Does parsing continue, or does 
parsing stop with no exception? Are you sure you aren't confusing 
well-formedness and validity errors? They aren't the same, and don't 
have the same effect.

If nothing else, you could always just rethrow the exception from your 
error handler. You have to do this for validity errors. I don't think 
you should have to do it for well-formedness errors though, but maybe 
that's changed. Do you have a reproducible test case?

-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org