xxexpr.ss – an SXML-to-XML converter

By: on October 11, 2005

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

My Page

Hello, world!

You can either browse the code, or retrieve it using

$ darcs get https://www.lshift.net/~tonyg/xxexpr/


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>