[XML-SIG] Switching back and forward between SAX and DOM
Thu, 06 Jun 2002 08:35:57 -0600
> Eric van der Vlist <email@example.com> writes:
> > How can you get a DOM tree out of SAX events (if for instance you've
> > developed a ContentHandler, can you retrieve a part of the document as
> > a DOM tree by forwarding the events to a DOM parser?)
> Depends on whether you have PyXML, or only Python proper. With
> minidom, there is xml.dom.ext.reader.Sax2, which takes a SAX parser;
> for PyXML, xml.dom.minidom.parse does the same thing. Notice that, in
> both cases, you need to pass an XMLReader. For minidom, the content
> handler that will build the DOM tree is xml.dom.pulldom.SAX2DOM
> (unless you need the pulldom functionality itself); for 4DOM, it
> is xml.dom.ext.reader.Sax2.XmlDomGenerator.
> > how can I serialize a DOM tree as SAX events which can be processed
> > by a ContentHandler?
> For PyXML, xml.dom.ext.Dom2Sax does that. In standard Python, that
> functionality is not available.
> Notice that you will have to experiment, and might find bugs, since
> that functionality is rarely used.
Well, I should have known Martin would have it all offhead :-).
It is pretty much as I'd thought. I don't recommend that Eric switch to 4DOM.
Not only has he already survived one traumatic switch, but it is a great step
backward, not least because 4DOM is excruciatingly slow.
I'll look to updating xml.dom.ext.reader.Sax2.XmlDomGenerator and
xml.dom.ext.Dom2Sax to general-purpose utilities for both PyXML and 4Suite
domlettes. Should go pretty quickly if I end up in enough boring sessions
here at XML One :-)
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Track chair, XML/Web Services One (San Jose, Boston):
DAML Reference - http://www.xml.com/pub/a/2002/05/01/damlref.html
The Languages of the Semantic Web - http://www.newarchitectmag.com/documents/s=
XML, The Model Driven Architecture, and RDF @ XML Europe -