[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: JAXP and SAX ErrorHandler stuff

  • From: Dylan Walsh <Dylan.Walsh@K...>
  • To: xml-dev@l...
  • Date: Fri, 04 May 2001 14:16:38 +0100

sax errorhandler
I have not read your email in detail, but can you not call the
getParser() method, which returns the underlying org.xml.sax.Parser, on
which you can then call setErrorHandler()?
I have never used SAX, but figured that out from reading the JavaDocs.

> -----Original Message-----
> From:	Mike Brown [SMTP:mike@s...]
> Sent:	Friday, May 04, 2001 2:07 AM
> To:	xml-dev@l...
> Subject:	JAXP and SAX ErrorHandler stuff
> 
> I feel like I'm really just not grasping something here.
> 
> The javax.xml.parsers abstract classes seem to exist for the purpose
> of
> making it so that I can code for them instead of for specific parsers.
> 
> Quoting from the ErrorHandler API docs, "WARNING: If an application
> does
> not register an ErrorHandler, XML parsing errors will go unreported
> and
> bizarre behaviour may result. For XML processing errors, a SAX driver 
> must use this interface instead of throwing an exception."
> 
> I would think that registering an ErrorHandler is something that is so
> essential to any SAX parsing operation that it would be a part of the
> JAXP classes. So I don't understand why a setErrorHandler method is
> not
> in the JAXP SAXParser abstract class.
> 
> I want to have my ErrorHandler output to a particular Writer, so my 
> approach has been the following (try/catch notwithstanding):
> 
>   import java.io.*;
>   import org.xml.sax.ErrorHandler;
>   import javax.xml.parsers;
> 
>   ...
> 
>   Writer myWriter = new CharArrayWriter();
>   ErrorHandler myErrorHandler = new ErrorHandler(myWriter);
>   SAXParserFactory factory = SAXParserFactory.newInstance();
>   SAXParser parser = factory.newSAXParser();
>   parser.setErrorHandler(myErrorHandler);  // breaks! no such method
>   parser.parse(whatever);
> 
> ...and then my ErrorHandler has a constructor that sets an output
> destination for its error messages to be the Writer that was passed
> in as an argument.
> 
> This doesn't work because setErrorHandler() doesn't exist in the
> abstract
> SAXParserFactory class. It only exists in the implementation's class
> that
> inherits from it, by virtue of that class's requirement to implement
> the
> SAX2 XMLReader interface.
> 
> It seems that I need to either work with XMLReader implementations and
> forget about using JAXP's SAXParserFactory and SAXParser, or import a
> particular implementation's classes and call them directly. This makes
> me
> wonder what the great advantage is to JAXP in SAX processing.
> 
> I thought perhaps the answer was that setErrorHandler() is not
> necessary, 
> because I could have my ErrorHandler not only implement 
> org.xml.sax.ErrorHandler, but also extend 
> org.xml.sax.helpers.DefaultHandler. Then I would have to omit the 
> ErrorHandler constructor and setErrorHandler call in the code above.
> 
> The problem with this is that I need to control the construction of
> the
> ErrorHandler so that I can have it output the error messages to a
> particular Writer. I have no idea what the implementation's SAXParser
> is
> going to do when it constructs a DefaultHandler, but I'm pretty
> certain
> there is no way for me to sneak my instance-specific Writer in there.
> 
> JAXP has an ErrorListener interface for XSLT processing errors. Why
> isn't
> there an equivalent for the XML parsing? What am I not understanding
> here?
> 
>    - Mike
> ______________________________________________________________________
> _______
> mike j. brown, software engineer at  |  xml/xslt: http://skew.org/xml/
> webb.net in denver, colorado, USA    |  personal:
> http://hyperreal.org/~mike/
> 
> ------------------------------------------------------------------
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To unsubscribe from this elist send a message with the single word
> "unsubscribe" in the body to: xml-dev-request@l...

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.