[XML-SIG] Proposal: Marrying SAX2 and DOM

Paul Prescod paul@prescod.net
Mon, 13 Mar 2000 11:45:15 -0800


Lars Marius Garshol wrote:
> 
> ...
>
> Also, ideally I would like to see several alternatives for easy XML
> application building on top of SAX (easySAX, Pyxie, saxdom?, ...),
> thus giving developers more than one alternative, and also making it
> more likely that what we end up with is the best (or at least most
> popular) variant.

I agree that higher level APIs should be built on top of SAX. I think we
should only have multiple higher level APIs if we determine that there
is a reason for bifurcation. The benefit of competition is choice and
evolution. The cost is confusion. We will also need to consider what
should go into the Python library itself. There was some concern that
SAX is not Pythonic (esp. easy enough) to replace xmllib (which is not
sophisticated enough).

I have prototyped my stab at a sort of "unification API" and I just need
two free days (hard to come by!) to finish the implementation and
documentation. I think it is pretty cool. I don't remember whether I
stole the DOM node idea from Ken or independently invented it (long,
sleepless nights...memory is fuzzy). I definately stole ideas from Pyxie
and what we had spoken about for easySAX.

I've been working on it for about two months but wanted a more
deterministic end date before I announced. I expect my "free days" to be
available in early April. (right now I am working on a very hectic
on-site project!)

I would really appreciate it if other people could look at it and give
me opinions. 

Here are the basic ideas:

 * handlers pass DOM nodes. (a la "Marrying" and Pyxie)
 * all parent nodes are available (not really that expensive usually)
 * peer and child nodes are not typically available
 * callbacks are labelled with *full XPaths* (a la XSLT)
	 * abuses "docstrings" (a la "spark")

def start_spam( self, textNode ):
    "figure/title/text()"
    print "Figure title:"+`textNode`
    print "tagname:"+textNode.parentNode.tagName

 * you can ask for an event to be handed to you as a tree

def start_applets(self,elementNode):
    "object/applet as tree"
    for node in elementNode.childNodes:
        print node

 * if you do, then child nodes are available
 * the tree disappears after the end event
 * handles namespaces

Here are slides of what I'm doing:

http://www.prescod.net/python/eventdom/

Opinions are solicited.

-- 
 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
Out of timber so crooked as that which man is made nothing entirely
straight can be built. - Immanuel Kant