Hi Flex Folks,

Is there a purpose-built incremental SAX Parser component available
for ActionScript?

Some background (please excuse the novella):

In a Flex project I shipped about 4 months ago, I needed to
accommodate a web-service that can sometimes return a large amount of
data.

I saw that many people recommend modification of the service (or
creation of an intermediate proxy) such that results are paged.

For that specific project, it turned out that I could actually modify
the service to produce paged output (as I had written the web-service
earlier)... but I was left feeling very uncomfortable about that as a
solution for a number of reasons. 

In most cases, I would not have the ability to alter the web-service,
so I'd be forced to create a proxy service... but this has many
disadvantages, the worst being that I'd have to make (a lot of)
bandwidth available for the proxy to run from my own servers, despite
all the data being available from third-party web-services; this has
ongoing cost implications for similar projects.

I found that with server-side paging, the user experience was degraded
unless I also created a paged DataGrid in my Flex UI. This was a
clumsy exercise as I could find no pre-built data-bound paging
component independent of any existing UIComponent. 

My users also reported that client-side paging is very
inconvenient for large datasets (I tried various page-set sizes). I
did not ship a useful feature (drag and drop re-ordering of rows) as
there was no way (without getting insanely complicated during drag) to
drop a bound row to "three pages ago near the bottom".

What I *really* wanted was something I've come to rely on in past
years: an incremental SAX parser. 

This is really standard fare in Perl/Python/Java/.Net/C++, so I'd
have thought something similar was available for ActionScript.

A SAX parser in combination with a WebService object and a Socket
object could form a very flexible event-based WebService-like component.

Alas I found nothing. The closest I came was the SAX parser included
in <a href="http://xmljs.sourceforge.net/";>XML4Script</a>; while it
was ECMAScript, it looked quite tedious to port/integrate.

I didn't have the time before, but I can see that it will be immensely
useful in the future. An event-based parser:
 * offers much more flexibility in Flex UI development, 
 * allows me to provide almost instant results/feedback to the user, 
 * uses constant memory (a requirement for large result-sets).

The SAXWebService could be a subclass of WebService, exposing another
"result"-like event "matchRow", but would return a fragment/object for
each matched row in the returned XML data and would do so as soon as
enough data has been received from the SOAP endpoint.

All the other pieces are there; here's how a SAXWebService would work:
1. Create a WebService object internally to fetch, validate and
   instantiate WSDL, and to obtain an endpoint.
2. Take some user supplied "matchRow" query (XPath) to match a row.
3. During the "send" method, open a seperate Socket connection.
4. Get the URLRequest from the WebService object, serialise and send
   to the endpoint over the socket.
5. Set up an event FSM such that when data is received from the 
   socket it is buffered.
6. A SAX event handler is written to match the available data 
   against the "match" query.
7. The SAX parser is fed the buffer (or perhaps an offset portion 
   of the buffer), which it parses as data becomes available.
8. The SAX parser will raise an event each time the query matches.
   The buffer can be optionally truncated (instead of using an
   offset) to enable constant-memory operation.

Am I missing some wonderful existing prior art? Has no other developer
requested this before? If not, I guess I'll have to find time to write it.

-David.


Reply via email to