FW: Problem with XMLReader

"Paul Brown" <[email protected]>
Newsgroups gmane.text.xml.sax.devel
Message-ID <7D365016E308F44EACB6ADB51CBD69041BEB58@shbex01.hosting.innerhost.com>
I failed to CC: the list on the response...

> From: [email protected] [mailto:[email protected]]
> 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 
> be configured at run-time. Writing an XMLReader for each is time 
> consuming, and hard because InputSources aren't a good fit to many data 
> 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


-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
List: sax-devel, [email protected]
See:  http://www.saxproject.org/
https://lists.sourceforge.net/lists/listinfo/sax-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.