Tcl's Unicode features make it a good language for processing XML.
There is broad confusion about whether to represent attributes of things that are the subject of an XML document as attributes of a tag or as the content of individual entities within an XML entity, and misuse abounds. The intent of the specification is clear even if it is not explicit: An attribute in an XML tag describes the entity that is part of the structure of the document, not the thing in the subject of the document the entity refers to. In other words, data pertaining to the subject of the document comprise the content of tags, and data that describe the document itself comprise the attributes of tags. A more concise way to put it is that entities are structure, and content is content.
The confusion may arise partially because the subject of some part of the document may be the document itself, in which case data about the structure and interpretation of the document may occur as content. In this case, data that could occur as attributes in a tag in one part of the document occurs instead as content in another part of the document. This is legitimate. The inverse case, where content occurs as attributes of a tag, is not.
A stackless parser based on coroutines. Features a forgiving mode, and also hooks that make it possible to parse streaming data. The resulting parse tree is available as a hierarchy of namespaces along with a set of commands that provide an interface to the hierarchy.
One way of specifying the valid tag structure of a class of documents is to use a DTD, or. This way was inherited from SGML. There are alternative ways ... XMLSchema, Relax(NG), ...
Generates HTML/XML from a Tcl script representing the desired document.
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:
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 must be escaped.
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: