If you are building only part of an XML document, use the
DocumentFragment constructor
instead of Document:
DocumentFragment ( nsMap )
where the nsMap is a dictionary that maps
namespace prefixes to namespace URIs, as in the Document constructor.
The constructor returns a new, empty document fragment. It has two methods:
.serialize ( outFile=None ) .write ( outFile=None )
Either of these methods will write the content of the
fragment to an output file. Its arguments are the same
as for the .serialize() and
.write() method of the Document
class; see Section 13.2.2, “
Document methods
”.
Attach content to a DocumentFragment the
same way you would to a Document: by
passing it as the first argument to an Element or other constructor.