[XML-SIG] More Pythonic XML creation

Andrew Clover and-xml at doxdesk.com
Sat Feb 12 15:37:36 CET 2005

John W. Shipman <john at nmt.edu> wrote:

> I've rewritten my document "Python and the XML DOM" to
> conform to the way the Python 2.3 xml.dom.minidom module
> wants you to use factory methods: see section 6, `Creating
> a document from scratch'

Actually you haven't quite gone far enough. Document and DocumentType 
should themselves be created from factory methods. You're supposed to 
use minidom.getDOMImplementation(), or the 'implementation' property of 
an existing Document to get a DOMImplementation object, then call 
createDocument() and createDocumentType() on it.

These constructors work for now, but can't be guaranteed; there are no 
constructors in the W3C DOM standard itself. Using the constructor for 
DocumentFragment, on the other hand, could well cause errors (like what 
you get with Element etc). Use Document.createDocumentFragment().

> I would greatly appreciate any comments.

 >> XML (eXtended Markup Language) and SGML (Standard General Markup 

eXtensible Markup Language and Standard Generalized Markup Language.

Possibly you wanted less nit-picky comments, but you've got to take what 
you can get eh?

Andrew Clover
mailto:and at doxdesk.com

More information about the XML-SIG mailing list