[XML-SIG] SAX Events to DOM Tree

Brian Quinlan brian at sweetapp.com
Fri Feb 18 15:06:34 CET 2005

Neil Benn wrote:
> Hello,
>    I have a couple of questions :
>          I'm looking for some code which takes SAX Events and converts 
> them to a DOM Tree, the sax events don;t have a namespace decleration - 
> however I'm lost, from this page 
> (http://pyxml.sourceforge.net/topics/howto/node10.html) I can see :
> dom.ext.reader
>    Classes for building DOM trees from various input sources: SAX1 and
>    SAX2 parsers, htmllib, and directly using Expat.
> However running help from the command line bring back a reader which 
> states that it can only receive streams of strings (I would expect it to 
> implement ContentHandler).  I also found a class on ActiveState 
> cookbooks but it only works with name spaced SAX events.  Before I go 
> about writing something is there a class which can do what I need?

 >>> help('xml.dom.ext.reader.Sax')

This module might do what you want.

>    The next bit is that the XMLGenerator only prints out code in one 
> huge big contiguous sequence of chars, I would like to have something 
> that pretty prints (with \t and \n) to the 'file-like' object (aka 
> output stream ;-)).  Again this seems like a common thing so I was gonna 
> check to see if I there is already a class that does this?

I'd don't know anything about XMLGenerator but the problem that you are 
likely going to have is that the serializer doesn't where whitespace 
can be added without changing the semantics of your document.

For example, this:


and this:


Would generate different DOMs (depending on the whitespace mode).
See here:

Maybe there is a flag to control this somewhere in the XMLGenerator 
(whatever that is) API.


More information about the XML-SIG mailing list