Here's an excerpt from my sexp to XML interface for Proverb:
Generating XML in Scheme
Proverb lets you generate and present XML-valued objects from Scheme with little fuss. The most crude interface is the procedure make-raw . This procedure is called with a valid XML fragment as a string and returns a new XML-valued object whose contents are that fragment.
Most users and procedures that generate XML values neither explicitly generate these corresponding XML string fragments nor embed XML string fragments directly in their programs.
Scheme values are transformed automatically into XML for the Proverb web interface and XML-valued objects can be generated more elegantly with the procedure with-xml-tag .
That example certainly looks a bit more like Scheme but papers over an irritating detail. The call to make-raw expects a string laden with XML markup. Any XML characters in the text would need to be escaped with entity codes. We would need to write:
When we generate XML for Scheme values that are not naturally XML, like Scheme strings, we go to some effort to provide the type of print fidelity provided by Scheme write . We put enough markup around these values to allow them to be distinguished in the browser. This decorates our classy ASCII with extra quotes and other styling.
We square this circle with the helper procedure make-text that generates free XML text from its string argument.
And which introduces a new detail of with-xml-tag . This procedure accepts as its first argument either a symbol naming an XML tag or a list naming an XML tag and encoding a number of XML tag attribute keys and values.
---------
The five referenced functions and syntax forms:
xmlize
xmlize-value
with-xml-tag
make-raw
make-text
have pretty straightforward definitions. The largest, and the one that most resembles your example kernel, is xmlize-value. Its definition is provided below:
While this seems to work, it has some drawbacks, which I can not figure out how to get rid of them:
- It doesn't work on pairs. When I uncomment the case which checks for pairs, the result is no longer XML. Instead, it looks more like the output of (display)
- There is no way to tell symbols from strings in the XML output.
- I'd like atoms to be enclosed into its tags without any whitespace. While it is easy to get rid of the indentation and the trailing newline, I can't figure out how to get rid of the newline that comes behind the opening tag
Any hints?
BTW: In addition, I'd appreciate any hints how to make this thing more scheme'ish. I think there is lots of potential for improvement here.