[XML-SIG] RAX
Ken MacLeod
ken@bitsko.slc.ut.us
03 May 2000 13:19:26 -0500
Lars Marius Garshol <larsga@garshol.priv.no> writes:
> * Ken MacLeod
> |
> | Since that's good for a reason, it may also be good if there were a
> | version of SAX that _was_ pull-style so that it could be used in
> | applications like RAX. In this way, one could stack SAX modules and
> | filters in a pull-style chain as an alternative to a push-style chain.
>
> I agree with this and have been thinking about this for a while, but
> I'm not sure how we would actually implement this. The only XML parser
> we have that supports a pull-style interface is RXP, and I'm not sure
> if we can convert the other interfaces to pull-style interfaces in a
> sensible way (at least not on a level as low as SAX) without storing
> the entire sequence of events.
>
> Good ideas are welcome...
I don't think existing push-style parsers need to be converted, or
implied that they could be used in a pull-style chain. I was thinking
more of creating the interface definition of a pull-style SAX parser
and allowing for new parsers to be developed rather than a wholesale
conversion of push-style parsers.
RXP and PYX are both good candidates for pull-style parsing.
I think an EasySAX-like approach would work best, where next_event()
returns a DOM/mini-DOM node:
node, is_end = pull_parser.next()
while node != None:
if node.nodeType == ELEMENT:
if is_end:
""" do end element processing """
else:
""" do start element processing """
elif node.nodeType == TEXT:
""" do text processing """
node, is_end = pull_parser.next()
Most of the rest of the SAX interface (sources, creating parsers,
exceptions, locators) could probably be used without change.
If two threads are used, any push-style parser can be used to queue
events to be read by a pull-style adapter in the other thread.
-- Ken