[plt-scheme] Generating HTML from s-expressions
William Sprague wrote:
>I think this is an RTFM, but I can't find the FM, so I will ask: how does
>one generate a string of HTML given an s-expression without doing this from
>a servlet? I want to write it to a file rather than use the webserver...
>
This particular FM entry is listed as "the XML collection" and be found
if you search for "XML" (DrScheme wants to handle HTML as XHTML, and
won't really support writing non-well-formed-XML HTML easily). The short
story:
(require (lib "xml.ss" "xml"))
to make an x-expr (= an s-exp suitably restricted) into a string, call
(xexpr->string <the-xexpr>):
> (xexpr->string '(html (body "hello")))
"<html><body>hello</body></html>"
You should also consider
> (display-xml/content (xexpr->xml '(html (body "hello"))))
<html>
<body>
hello
</body>
</html>
[printed to the current output port rather than returned, so use
with-output-to-file to redirect to the appropriate file]
Hope that helps.
-jacob