[XML-SIG] Pretty-printing DOM trees
Fri, 22 Jan 1999 19:00:55 +0100
A.M. Kuchling wrote:
> The format() function below pretty-prints a DOM tree. It strips away
> all the whitespace, and then inserts Text nodes containing white
> space, producing output like this:
> <?xml version="1.0"?>
> <?IS10744:arch name="xsa"?>
> <TITLE>xmlproc: A Python XML parser</TITLE>
> <META xsa='last-release' VALUE='19980718'/>
> <SPAN xsa='name'>xmlproc</SPAN>: A Python XML parser
> Should this be left as just a black-box function, or should it be
> implemented as a subclass of the writer.XmlWriter() class? I suppose
> it depends on the envisioned application for this; if it's just to
> make output a little bit more readable for debugging purposes, then
> customizability isn't very important. On the other hand, if people
> will want to do careful indenting of the output, indenting some tags
> and not others, then the XmlWriter solution is the way to go.
> My inclination is to the former view, but then, that's also easier for
> me. :) Thoughts?
Well, thank you - this was exactly what I wanted.
Just readable output. I took it as is, named it "format.py",
perfect. I don't think that customization is such an issue.
Maybe it could be a drawback that applying format to a dom was
about three or four times slower than creating the dom at all,
Would this function belong to xml.dom.utils, besides print_tree?
But it is actually a function wich happens to use DOM for its
work, so it seems to be a more general function for all xml
modules, so xml.utils may be better.
Then I could also think of recoding it as an sgmlop app.
Thanks again - chris
Christian Tismer :^) <mailto:email@example.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.skyport.net
10553 Berlin : PGP key -> http://pgp.ai.mit.edu/
we're tired of banana software - shipped green, ripens at home