From: Lars H. <Lar...@re...> - 2010-06-17 16:32:20
|
Lately, a lot of the projects I've been working on have involved (i) generating Tcl data structures that could be viewed as a particular encoding of part of an XML document and (ii) converting said data structures to XML on output. While (i) is always rather specific, the (ii) part tends to be very generic, and while it's code-wise very short, it kind of worries me that I'm copying the same procedures from project to project, so I've been thinking "maybe this should go into tcllib?" As a matter of fact, I've been somewhat surprised to not already find something along these lines in there, but maybe it's too elementary to make a package for... The intent is not to provide industrial capacity XML handling (there are well-known compiled extensions for that), but rather to provide a cheap package that you can put into your script when you just want to add XML as another output format. The latest version of my command is TDLtoXML::xml_from_trees (but never mind the namespace) on http://wiki.tcl.tk/25681#pagetocbc2b8a8c. This coverts from a tdom list format to XML (cf. http://wiki.tcl.tk/26156), and that is perhaps something that should be scrutinised, since putting something like this in tcllib is an act of blessing its data format. Comments, anyone? Lars Hellström |
From: Andreas K. <and...@ac...> - 2010-06-17 16:56:09
|
Lars Hellström wrote: > Lately, a lot of the projects I've been working on have involved (i) > generating Tcl data structures that could be viewed as a particular > encoding of part of an XML document and (ii) converting said data > structures to XML on output. > > While (i) is always rather specific, the (ii) part tends to be very > generic, and while it's code-wise very short, it kind of worries me > that I'm copying the same procedures from project to project, so I've > been thinking "maybe this should go into tcllib?" As a matter of fact, > I've been somewhat surprised to not already find something along these > lines in there, but maybe it's too elementary to make a package for... The doctools support TMML as output format, which is a XML format. Joe English wrote that plugin (IIRC), and provided tcllib/modules/doctools/mpformats/_xml.tcl containing the more generic support code. This is not a package outright, just a file which is dt_source'd by the {fmt,toc}.tmml files/engines. The _html in mpformats also has bit of generic tag generation. > The intent is not to provide industrial capacity XML handling (there > are well-known compiled extensions for that), but rather to provide a > cheap package that you can put into your script when you just want to > add XML as another output format. > > The latest version of my command is TDLtoXML::xml_from_trees (but never > mind the namespace) on http://wiki.tcl.tk/25681#pagetocbc2b8a8c. This > coverts from a tdom list format to XML (cf. http://wiki.tcl.tk/26156), > and that is perhaps something that should be scrutinised, since putting > something like this in tcllib is an act of blessing its data format. > > Comments, anyone? Not yet, will have to make the time for a look. -- Andreas Kupries Senior Tcl Developer ActiveState, The Dynamic Language Experts P: 778.786.1122 F: 778.786.1133 and...@ac... http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog |
From: Andreas K. <and...@ac...> - 2010-06-17 18:55:27
|
Lars Hellström wrote: > Lately, a lot of the projects I've been working on have involved (i) > generating Tcl data structures that could be viewed as a particular > encoding of part of an XML document and (ii) converting said data > structures to XML on output. > > While (i) is always rather specific, the (ii) part tends to be very > generic, and while it's code-wise very short, it kind of worries me > that I'm copying the same procedures from project to project, so I've > been thinking "maybe this should go into tcllib?" As a matter of fact, > I've been somewhat surprised to not already find something along these > lines in there, but maybe it's too elementary to make a package for... > The intent is not to provide industrial capacity XML handling (there > are well-known compiled extensions for that), but rather to provide a > cheap package that you can put into your script when you just want to > add XML as another output format. > > The latest version of my command is TDLtoXML::xml_from_trees (but never > mind the namespace) on http://wiki.tcl.tk/25681#pagetocbc2b8a8c. This > coverts from a tdom list format to XML (cf. http://wiki.tcl.tk/26156), > and that is perhaps something that should be scrutinised, since putting > something like this in tcllib is an act of blessing its data format. "The trick is to parse TDL data by evaluating it in an empty slave interpreter." Are you limited to Tcl 8.4 ? If not, i.e. 8.5 is viable, then usage of a namespace and 'namespace unknown' may allow us to forego the empty slave. What I am missing is some explanation on how you envision the dnyamic creation of TDL structures. Plain [list] commands ? Right now I only see static structures on the page, and their conversion to other formats (data tress, pretty printing, ...) Having read this I now also see that the _xml.tcl I mentioned in my first mail is more of a low level generator which would be driven by such data structures. Assembler in essence, versus your HLL. The xmlgen/htmlgen refeenced on your pages are much more comparable to the _xml.tcl -- Andreas Kupries Senior Tcl Developer ActiveState, The Dynamic Language Experts P: 778.786.1122 F: 778.786.1133 and...@ac... http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog |
From: Lars H. <Lar...@re...> - 2010-06-18 08:18:19
|
Andreas Kupries skrev: > Lars Hellström wrote: >> Lately, a lot of the projects I've been working on have involved (i) >> generating Tcl data structures that could be viewed as a particular >> encoding of part of an XML document and (ii) converting said data >> structures to XML on output. [snip] >> The latest version of my command is TDLtoXML::xml_from_trees (but >> never mind the namespace) on http://wiki.tcl.tk/25681#pagetocbc2b8a8c. >> This coverts from a tdom list format to XML (cf. >> http://wiki.tcl.tk/26156), and that is perhaps something that should >> be scrutinised, since putting something like this in tcllib is an act >> of blessing its data format. Note that TDL is just one of the projects where XML generation pops up. One could envision a package for both TDL and XML, but it's not something I'm suggesting here and now. > "The trick is to parse TDL data by evaluating it in an empty slave > interpreter." > > Are you limited to Tcl 8.4 ? If not, i.e. 8.5 is viable, then usage of > a namespace and 'namespace unknown' may allow us to forego the empty slave. No, for security reasons that wouldn't be good; you can always give a fully qualified named even from within a given namespace. > What I am missing is some explanation on how you envision the dnyamic > creation of TDL structures. Plain [list] commands ? Right now I only see > static structures on the page, and their conversion to other formats > (data tress, pretty printing, ...) For dynamic generation, you might instead want to look at Part III of http://abel.math.umu.se/~lars/mtmtcl/interfaces.pdf (page 79 and forth); that's one of the other projects. In yet another project, I've been generating SVG for inlining into XHTML... > Having read this I now also see that the _xml.tcl I mentioned in my > first mail is more of a low level generator which would be driven by > such data structures. Assembler in essence, versus your HLL. I'll have to take a look at it. Must rush now. > The xmlgen/htmlgen refeenced on your pages are much more comparable to > the _xml.tcl Lars Hellström |
From: Lars H. <Lar...@re...> - 2010-06-21 15:06:06
|
Andreas Kupries skrev: > Having read this I now also see that the _xml.tcl I mentioned in my > first mail is more of a low level generator which would be driven by > such data structures. Assembler in essence, versus your HLL. > > The xmlgen/htmlgen refeenced on your pages are much more comparable to > the _xml.tcl Having looked at _xml.tcl myself, I'd summarise the differences roughly as follows: _xml.tcl is indeed "assembler", in that it generates start- and end-tags separately (though with some facilities for automating closing of elements). xmlgen and my procedures are higher level, which make it more difficult to mess things up, but probably also increases memory requirements. A difference between my approach on one hand and that of _xml.tcl and xmlgen on the other is however that the former (re)encodes an existing data structure as XML, whereas the latter generate it on the fly; a [trace] of one's program when using these two will correspond fairly directly to the structure of the XML being generated. Lars Hellström |