From: Steve B. <Ste...@zv...> - 2003-07-17 12:31:59
|
Maria M. Yu wrote: > I am trying to test to see if I could use Tcl for dynamic XML as it's > claimed by tcltk. > > Basically, I want to create a base xml document and then supply scripts > to fill in various parts of the base xml document with dynamic data. > > Do you have anything that could help with my implementation? I can think of a couple of different ways to achieve this. Firstly, the simplest approach may be the "microscripting" technique. The technique involves embedding Tcl scripts in your XML document and then use the 'subst' command to resolve the scripts. This approach was first developed for HTML documents in the NeoWebServer and tclhttpd Web servers. For example: <article> <title>$title</title> <para>The time is [clock format [clock seconds]].</para> </article> Notice how the Tcl scripting and XML are intimately tied together. From an XML purist point-of-view, another approach is to use XSLT. XSLT is very good at dynamically creating XML documents. Parameters can be passed into the stylesheet as required. Even more sophisticated is to use TclXSLT - XSLT combined with Tcl extensions. With TclXSLT you can make calls into Tcl scripts from an XSL stylesheet. The following example is a 'literal result element as a stylesheet': <article xsl:version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:tcl='urn:my-tcl-extension' extension-element-prefixes='tcl'> <title><tcl:variable name='title'/></title> <para>The time is <tcl:format-time/>.</para> </article> The Tcl script(s) that implement the 'tcl:' extension elements are not shown here. This approach separates the Tcl code from the XML/XSLT document, which is certainly a desirable characteristic. However, you will notice that the overheads are high so it is up to you as to whether that is acceptable. There are other approaches - xmlgen springs to mind, as well as using TclDOM to navigate and modify the document. Hope that helps, Steve Ball -- Steve Ball | XSLT Standard Library | Training & Seminars Zveno Pty Ltd | Web Tcl Complete | XML XSL Schemas http://www.zveno.com/ | TclXML TclDOM | Tcl, Web Development Ste...@zv... +---------------------------+--------------------- Ph. +61 2 6242 4099 | Mobile (0413) 594 462 | Fax +61 2 6242 4099 |