Next / Previous / Contents / TCC Help System / NM Tech homepage

13. A more Pythonic module for XML file creation

The techniques described in the section above, Section 12, “Creating a document from scratch: factory methods”, are somewhat clumsy. This clumsiness is due to the DOM's language-independent charter.

Here, in “literate programming” style, is a small Python module named that gives you a more Pythonic tool for XML file creation. For more on literate programming, see A source extractor for lightweight literate programming.

For links to the source files developed here, see Section 1.1, “How to get this publication”.

Here are the classes exported by the module.

13.1. The DocumentType class

If your document is to have a <!DOCTYPE ...> declaration attached, you must create a DocumentType object with that information before creating your Document object, because the document type is an argument to the Document constructor.

The constructor has this calling sequence:

DocumentType ( rootGI, publicId, systemId )

The arguments are:


The qualified name of the root element.


The public identifier, if any, as a string. To get a <!DOCTYPE rootGI SYSTEM ...> document type identifier, pass None as this argument.


The system identifier as a string. Required.