Sorting through Twisted Matrix is reminiscent of the old story about blind men and elephants. Twisted Matrix has many capabilities within it, and it takes a bit of a gestalt switch to get a good sense of why they are all there.
| Sorting through Twisted... | a good sense of why they are ... WHAT ELSE? ------------------------------------------------------------------------ As well as its equivalents for SAX and DOM (i.e. the native Scheme nested lists), [SSAX] comes with its own [SXPath] and [SXSLT] components. This article does not have room for extensive discussion of these, but they are worth mentioning briefly. Unfortunately, the [SXPath] and [SXSLT] functions and macros discussed in Oleg Kiselyov's document "XML, XPath, XSLT implementations as SXML, SXPPath and SXSLT" are not included in the [SSAX] distribution, at least not the one for Guile (other distributions are available for a number of Scheme systems). What can be easily downloaded only works with a few Scheme-systems, and versioning is unclear. Based just on the document mentioned, SXPath works much like XPath. For example, either of the following expressions expand to a selection function: #----------- SXPath expressions, native and textual -------------# ((sxpath '(// TAF VALID @ Trange *text)) document) ((txpath "//TAF/VALID/@TRange/text()") document) These undergo macro expansion to: #----------------- Full path selector function ------------------# ((node-join (node-closure (node-typeof? 'TAF)) (select-kids (node-typeof? 'VALID)) (select-kids (node-typeof? '@)) (select-kids (node-typeof? 'TRange)) (select-kids (node-typeof? '*text*))) document) Of course, playing with this expanded form would allow programming arbitrary calculations inside an XPath-like selector--anything you can write in Scheme. SXSLT is similar in concept. Stylesheets are written in Scheme form that is semantically similar to XSLT. But much as with the flexibility of [HaXml], within any particular transformation rule, you can embed arbitrary extra code. Particular XSLT engines, of course, often come with foreign-function APIs to write extra capabilities in Javascript, VB, or other languages. But with SXSLT, the custom functions are written in the very same Scheme language as the transformation stylesheet elements. CONCLUSION ------------------------------------------------------------------------ I like the [SSAX] library quite a bit; and I suspect I will like it more as I become more comfortable with Lisp/Scheme.programming. It shares many of the advantages of other "native" XML libraries I have written about in other installments: [gnosis.xml.objectify], [REXML], [XML::Grove], [HaXml], and so on. There's a lot to be said for making XML into -just another data object- in whatever programming language you use. That said, [SSAX] has a lot of rough edges. It is hard to figure out what to download, and what Scheme systems each part is available for. The documentation is somewhat inconsistent and incomplete--most of the documents are academic in focus, and do more to discuss abstract goals and concepts than on concrete usage and API. As a demonstration of what is possible in Scheme--using functional techniques--these papers are interesting; but it would be nice to have something that is easy to install and use, and -just works-. RESOURCES ------------------------------------------------------------------------ The homepage for SXML is below. A number of overlapping documents are available on that site, mostly written by Oleg Kiselyov: http://okmij.org/ftp/Scheme/xml.html To download version of the [SSAX] library for various Scheme systems, see: http://www196.pair.com/lisovsky/xml/ssax/ The [SXPath] extension appears to be available at the below page, but unfortunately not for Guile: http://www196.pair.com/lisovsky/query/sxpath/ The XML Information Set (Infoset) is a W3C Recommendation that specifies the information content of XML documents; i.e. it indicates which features of a concrete document carry information, and which are incidental. http://www.w3.org/TR/xml-infoset/ The version of Scheme I used for this article is the GNU project's Guile. Other versions, both commercial and free software exist as well, but Guile seems widespread--and it is the version that 'fink' will install under MacOSX. The Guile home page is at: http://www.gnu.org/software/guile/docs/index.html A previous installment of this column discussed the XML library [HaXml] for the functional programming language Haskell. While Haskell is purer in its functional programming paradigm, many common motivations and designs went into HaXml and SXML. http://www-106.ibm.com/developerworks/xml/library/x-matters14.html Ed Dumbill wrote an article called "Exploring alternative syntaxes for XML" for developerWorks: http://www-106.ibm.com/developerworks/xml/library/x-syntax.html Scott Sweeney has also produced a nice visual summary of syntax varations of near-XML languages: http://www.scottsweeney.com/static/projects/slip/XMLShorthandComparison.htm ABOUT THE AUTHOR ------------------------------------------------------------------------ {Picture of Author: http://gnosis.cx/cgi-bin/img_dqm.cgi} David Mertz once led the desperate life of scholarship. David may be reached at mertz@gnosis.cx; his life pored over at http://gnosis.cx/publish/. Suggestions and recommendations on this, past, or future, columns are welcomed. Check out David's new book _Text Processing in Python_.