[XML-SIG] Repost: DOM notes

Andrew Kuchling akuchlin@cnri.reston.va.us
Mon, 20 Apr 1998 12:35:19 -0400 (EDT)

I've written a first cut at a marshal module that converts a simple
Python data structure to and from a simple XML representation, using
the DOM implementation.  The code's available in the SIG archive.
Some notes:

        * There's one problem with xml.marshal at the moment; you
can't pickle multiple objects to the same stream because, when you
read the data again, the parser doesn't read one data item and stop,
but reads them all.

        For example, None is converted to a <none/> tag; if you pickle
None to the same file object twice, you get <none/><none/>.  But when
you parse this, the parser builds a tree containing both tags.  If an
XML document must contain a single top-level element, then I think
parsers should recognize when that top-level element has been
completed and stop.  

        Any thoughts on this question?  What's the correct behaviour?

        * The Walker class's walk1() method isn't consistent in
returning values.  walk() does "return self.walk1()", but walk1() 
never returns anything; this should probably be fixed.  For
xml.marshal, I therefore overrode the walk1() method, but I'm not sure
that's how Walker is intended to be used.

        On the other hand, unmarshalling using just startElement(),
endElement(), and doText() would have been more complicated, so
overriding was the easiest thing to do.

A.M. Kuchling			http://starship.skyport.net/crew/amk/
Our advanced and fashionable thinkers are, naturally, out on a wide swing of
the pendulum, away from the previous swing of the pendulum. If you want to
reach dead center, you will do well to avoid the most advanced thinkers.
	-- Anthony Standen