View Single Post
Old Aug 28th, 2006, 4:24 PM   #8
alcdotcom
Programmer
 
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0 alcdotcom is on a distinguished road
Here's another article you might find useful. This one addresses a way to stop the SAX parser in mid parse. Tere is no built-in way to stop a SAX parser, so the gist is that you have to throw a SAXException to stop it. Why would you want to do this? Well, imagine this scenario. You load a feed, not knowing what type it is (RSS, ATOM, etc). You have parser who's sole purpose is to detemine what type of feed it is and then hand it off to an instance of the appropriate parser type. You could allow it to parse the entire document, reading only the first element to get the type, or you could abort the parsing after the type is obtained. Obviously, aborting the parse could save you loads of time, especially if you've got lots of documents to parse or a long document. Otherwise you're parsing it twice. What I did was create a sub-class of SAXParserException called ParsingAbortException (doesn't matter what you call it). This way, you can easily differentiate between your exception and actual SAXParserExceptions.
__________________
Java Blog
alcdotcom is offline   Reply With Quote