[XML-SIG] Pretty-printing DOM trees

Andrew M. Kuchling akuchlin@cnri.reston.va.us
Thu, 21 Jan 1999 18:16:12 -0500 (EST)


Christian Tismer writes:
>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,
>but nevermind.

	Hmm... wonder why it's so slow.  One reason might be that, for 
every element, it checks whether any of its children are also
elements, in order to format the two cases differently.  (As in:
  <head>
    <title>Text</title>
  </head>

It's not formatted as 
  <title>
Text
  </title>

>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.

	But it requires that you already have a DOM tree created, so
it seems best left in xml.dom.utils.  Indenting a document using SAX
or sgmlop might be best implemented as a specialized handler, not by
the expensive process of creating a DOM tree.

	I'll try to recast it into a subclass of XmlWriter, and have
utils.indent_tree() as shorthand to create and use an instance of that
subclass.  That gives both flexibility and quick-and-dirty
convenience.

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
It is true greatness to have in one the frailty of a man and the security of a
god.
    -- Seneca