[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: JAXP and SAX ErrorHandler stuff
- From: Dylan Walsh <Dylan.Walsh@Kadius.Com>
- To: xml-dev@lists.xml.org
- Date: Fri, 04 May 2001 14:16:38 +0100
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@skew.org]
> Sent: Friday, May 04, 2001 2:07 AM
> To: xml-dev@lists.xml.org
> 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@lists.xml.org