[XML-SIG] Child nodes and lazy evaluation (Generators)

Ken MacLeod ken@bitsko.slc.ut.us
23 Nov 2000 09:15:48 -0600

"Ken" <kens@sightreader.com> writes:

> I've written a Generator class which puts lazy evaluation
> functionality into a sequence object.  Seems to me that this would
> be a good thing use as an iterator for streaming XML/DOM child
> nodes.  I don't have time right now to integrate it myself, but it
> would be a fairly easy task.
> The result would be to hide the details of event driven streaming
> protocol within a pythonic interface that syntactically behaves like
> a fully loaded tree (thus solving the old "tree vs. events"
> dillemma).
> An example of how I have used generators is a readlines method of a
> simulated file object that returns a generator rather than a list.
> I was able to connect a stream 'f' to a serial port or socket (which
> might not have an EOF anytime soon) and then:
> for line in f.readlines():
>     do_something(line)
> ... which does -not- block on reading the end-of-file as you would
> normally expect.
> If you decide to take up this project please let me know.
> http://starship.python.net/crew/seehof/Generator.html

This sounds like an excellent utility for a "pull DOM parser", where
you receive DOM events as you ask for them, out of a queue.  In a
basic "pull DOM parser" though, no real magic is necessary as long as
you have an incremental parser feeding the DOM builder.

James Clark's Jade DSSSL processor uses a similar technique for
manipulating partial groves.  Jade had the ability to be parsing the
source file and doing the transform in parallel, if any node requested
was not yet parsed, the node request would block until the parser
thread caught up.

  -- Ken