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 xml4create.py 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 xml4create.py module.
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:
rootGI
The qualified name of the root element.
publicId
The public identifier, if any, as a string. To get
a <!DOCTYPE
document type identifier, pass rootGI SYSTEM ...>None as this argument.
systemId
The system identifier as a string. Required.