technology from back to front – an SXML-to-XML converter

The SSAX XML parsing- and processing-library provides robust, high-quality XML reading tools for Scheme, but doesn’t include a general purpose XML writer. Over the past couple of years, a few of my projects have had a need to convert SXML-like data to an XML 1.0 external representation, and so I’ve written a portable SXML-to-XML printing library (both a snapshot and a darcs repository). The library has been used with Chicken, MzScheme, and SISC, and currently includes module wrappers for Mzscheme and SISC (or other psyntax-based Schemes).

The library is parameterized over a choice of double- or single-quotes for attribute printing, and can, if required, be instructed to use explicit close-tags when an empty-tag is encountered. It provides procedures for producing a string representation of an XML fragment, for printing an XML fragment directly to a port, and for pretty-printing an XML fragment with indentation. For example,

(let ((title “My Page”))
‘(*pi* xml (version “1.0″))
`(html (head (title ,title))
(body (h1 ,title)
(p “Hello, world!”))))))

produces the following output (don’t mind the invalid XML PI, that’s something WordPress is doing – the actual output from the library is well-formed!):

< ?xml version='1.0'?>

My Page

Hello, world!

You can either browse the code, or retrieve it using

$ darcs get


4 − three =

2000-14 LShift Ltd, 1st Floor, Hoxton Point, 6 Rufus Street, London, N1 6PE, UK+44 (0)20 7729 7060   Contact us