[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: firstname.lastname@example.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:email@example.com]
> Sent: Friday, May 04, 2001 2:07 AM
> To: firstname.lastname@example.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
> making it so that I can code for them instead of for specific parsers.
> Quoting from the ErrorHandler API docs, "WARNING: If an application
> not register an ErrorHandler, XML parsing errors will go unreported
> 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
> 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
> ...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
> SAXParserFactory class. It only exists in the implementation's class
> inherits from it, by virtue of that class's requirement to implement
> 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
> wonder what the great advantage is to JAXP in SAX processing.
> I thought perhaps the answer was that setErrorHandler() is not
> 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
> ErrorHandler so that I can have it output the error messages to a
> particular Writer. I have no idea what the implementation's SAXParser
> going to do when it constructs a DefaultHandler, but I'm pretty
> there is no way for me to sneak my instance-specific Writer in there.
> JAXP has an ErrorListener interface for XSLT processing errors. Why
> there an equivalent for the XML parsing? What am I not understanding
> - Mike
> mike j. brown, software engineer at | xml/xslt: http://skew.org/xml/
> webb.net in denver, colorado, USA | personal:
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> 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: email@example.com