XML, or eXtensible Markup Language, is a data format.
[XML pretty-printing]: tDOM builds-in a pretty-printing serialization option. Those with an interest in a comparable function for TclDOM are welcome to try/use/improve [http://phaseit.net/claird/comp.lang.tcl/dom_pretty_print.html%|%dom_pretty_print].
[http://www.xml.org/%|%xml.org]
[http://web.archive.org/web/20110727035158/http://ldn.linuxfoundation.org/column/untaught-xml-schema%|%Untaught XML Schema] ,[Cameron Laird] ,2009-06-05
XML is a simplified form of SGML, but stricter (more regular) in some aspects:
Example:
<father name="Jack" att1="1"> <child name="Tom" born="1997" /> </father>
Tcl's excellent Unicode abilities make it a good language for processing XML.
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.
See Also:
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), ...
See Also:
See Also:
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:
proc asXML {content {tag document}} { set XML_MAP { < < > > & & \" " ' ' } return <$tag>[string map $XML_MAP $content]</$tag> }
Naturally, the XML_MAP variable is factorisable...
MHo: Why not using html::quoteFormValue for this purpose?
For generation of XML (HTML) the pure Tcl way, have a look at the xmlgen module of TclXML
DKF: That's when you're moving away from cheap hacks. And HTML has a lot more entities than XML, though most are optional.
If you want to get particular about entity encoding arbitrary text, this is working for me:
variable entityMap [list & &\; < <\; > >\; \" "\;\ \u0000
See Also:
There are a whole host of technologies related to XML:
[DTD] and XMLSchema: for specifying document schemas
tDOM and TclXML both provide good support for at least XPath and XSLT.
XML by itself is just a partially-standardized syntax for data. It's used as the basis for a variety of different applications, such as:
Various configuration file formats (especially in the [Java] world)
Alternatives to using XML for data files include: