xmlgen / htmlgen

xmlgen/htmlgen , by Harald Kirsch, is a system of generating HTML/XML.

Attributes

What:xmlgen / htmlgen
Where:http://sourceforge.net/projects/tclxml/
Description:Extension for easy, dynamic creation of HTML/XML with Tcl. Works in a fashion similar to cgi.tcl. xmlgen can be used to generate XML; htmlgen is built on top of xmlgen to generate HTML.
Currently at 1.4.0.
Updated:2002-05
Contact:mailto:[email protected] (Harald Kirsch)

See Also

XML Clean-Up

Description

SC: I've just been reading about Genx [L1 ] which is a C library for generating XML written by Tim Bray. The main differences between the capabilities of xmlgen and Genx seem to be:

  • Handling of XML Namespaces
  • Generation of Canonical XML [L2 ]

So, I had a quick think about how to do namespaces with xmlgen and came up with the following syntax:

 xmlns rdf "http://http://www.w3.org/1999/02/22-rdf-syntax-ns\#"
 xmlns rdfs "http://www.w3.org/2000/01/rdf-schema\#"

 declaretag foo -namespace rdf
 declaretag bar -namespace rdfs

 foo ! {
     bar - This is content
     bar - this is also content
 }

To make this work, the root element should have the namespace declaration attributes included:

 <foo xmlns:rdf="http..." xmlns:rdfs="http...">
   <bar>...</bar>
 </foo>

A quick look at the code makes me think that this modification might not be too hard to make (add the ns attributes in makeTagAndBody when the indent is "" -- or perhaps more properly add a nesting counter and add the attributes when it's zero). Having figured this out I might well go an implement this next time I need to generate XML with namespaces, this note is just in case anyone else wants to have a go instead.

jcw 2005-11-09: For a somewhat unconventional use of this package, see An indentation syntax for Tcl, end of page.