tDOM builds-in a pretty-printing serialization option. Those with an interest in a comparable function for TclDOM are welcome to try/use/improve dom_pretty_print .
surveys the state-of-the-art as of spring 2001, mainly from a Zveno-biased perspective. One deficiency of that article is its neglect of Jochen Loewer's tDOM work.
Amusingly enough, Microsoft has also in August 2009 been ordered to stop selling their Word product because of its XML functionality: Injunction on Microsoft Word unlikely to halt sales , Nancy Gohring, 2009-08-11.
tDOM and TclXML/TclDOM are the two main Tcl extensions for parsing XML, providing both SAX parsing for stream-oriented parsing, and DOM for document-oriented parsing.
One way of specifying the valid tag structure of a class of documents is to use a Document Type Definition, DTD for short. This way was inherited from SGML. There are alternative ways ... XMLSchema, Relax(NG), ...
In a mailing list conversation [reference?], Steve Ball succinctly advised, "When creating XML, I generally use TclDOM. Create a DOM tree in memory, and then use 'dom::DOMImplementation serialize $doc' to generate the XML. The TclDOM package will make sure that the generated XML is well-formed.
Alternatively, XML is just text so there's no reason why you can't just create the string directly. Eg:
puts <document>$content</document>
The problem with this is that (a) you have to worry about the XML syntax nitty-gritty and (b) the content variable may contain special characters which you have to deal with.
There are also some generation packages available, like the 'html' package in tcllib (this will be added to TclXML RSN, when my workload permits)."
DKF: If you're going for the cheap-hack method of XML generation mentioned above, you'll want this: