[XML-SIG] Switching back and forward between SAX and DOM
Martin v. Loewis
06 Jun 2002 09:03:24 +0200
Eric van der Vlist <firstname.lastname@example.org> 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
> 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.