[FRPythoneers] xml woes

Matt Gushee mgushee at havenrock.com
Fri Sep 6 12:38:27 MDT 2002


On Fri, Sep 06, 2002 at 10:23:51AM -0600, Karl Putland wrote:
> Days of pain later and still searching for the answer.
> 
> Trying to create a document using xml.dom.minidom or anything that will
> work.  Not from an existing document, but from scratch.
> 
> Problem is, that I can't get the <!DOCTYPE ...> tag to print out.
> 
> How in the world does this work?
> 
> I've parsed a document with a <!DOCTYPE> directive.  It appears as the
> doctype attribute of the document.  Then call document.toprettyxml(),
> and there is no DOCTYPE>

Karl, instead of toprettyxml(), try this (you'll need PyXML installed):

   from xml.dom.ext.Printer import PrintWalker, PrintVisitor

   f = open('foo.xml','w')
   v = PrintVisitor(f, 'iso8859-1', indent='  ')
   w = PrintWalker(v, document)
   w.run()
   f.close()

Works for me.

-- 
Matt Gushee
Englewood, Colorado, USA
mgushee at havenrock.com
http://www.havenrock.com/



More information about the FRPythoneers mailing list