FW: [Sax-devel] Problem with XMLReader
Brought to you by:
dmegginson
From: Paul B. <pr...@fi...> - 2002-06-27 13:26:30
|
I failed to CC: the list on the response... > From: Joe...@vw... [mailto:Joe...@vw...] > public interface ContentHandlerSource > { > /** > * Call this method to get an XML document streamed to you via the > * passed ContentHandler > */ > void writeToContentHandler(ContentHandler h) throws SAXException; > } > The logic behind it - sources of SAX events sometimes need to=20 > be configured at run-time. Writing an XMLReader for each is time=20 > consuming, and hard because InputSources aren't a good fit to many = data=20 > sources (in-memory, DBs, etc). Suggestions: 1) InputSource isn't final and XMLReader is an interface, so you can = make your own versions that may be incompatible with other objects. For = example, if you have an XMLReader implementation that turns a JDBC = rowset into a stream of SAX events, then you are free to subclass = InputSource to get a JDBCRowsetInputSource that has get/setStatement() = and get/setConnection() methods, etc., and then have an XMLReader = implementation that does: public void parse(InputSource is) throws SAXException { if (!(is instanceof JDBCRowsetInputSource)) { throw new SAXException(is.getClass().getName() + " is not " "a subclass of JDBCRowsetInputSource"); } /* DO STUFF HERE */ } This particular suggestion is intended to provide a reasonable level of = compatibility with other SAX consumers. For instance, if you're using a = TrAX-compliant XSLT processor, when it receives a SAXSource (XMLReader / = InputSource pair), it does (or should do): ss.getXMLReader().parse(ss.getInputSource()); to generate events. It's up to you to be sure that the InputSource = subclass and XMLReader implementation are compatible. 2) You can create your own abstract class that has a = pullFromSAX(XMLReader xr, InputSource is) method that attaches a = ContentHandler, etc., and then calls parse on the supplied InputSource. 3) You can create a utility class with a static method that accepts a = ContentHandler (and DeclHandler, etc., too?), XMLReader, and InputSource = tuple and then performs the relevant operations. In this case, your = writeToContentHandler() would be equivalent to = UtilityClass.consume(this,myXR,myIS); Just some pre-coffee suggestions. -- Paul |