Formatting XML

The easiest way to generate HTML or XML output is to run Kawa with the appropriate --output-format option.

The intentation is that these output modes should be compatible with XSLT 2.0 and XQuery 1.0 Serialization. (However, that specifies many options, most of which have not yet been implemented.


Values are printed in XML format. "Groups" or "elements" are written as using xml element syntax. Plain characters (such as ‘<’) are escaped (such as ‘&lt;’).


Same as xml, but follows the xhtml compatibility guidelines.


Values are printed in HTML format. Mostly same as xml format, but certain elements without body, are written without a closing tag. For example <img> is written without </img>, which would be illegal for html, but required for xml. Plain characters (such as ‘<’) are not escaped inside <script> or <style> elements.

To illustrate:

$ kawa --output-format html
#|kawa:1|# (html:img src:"img.jpg")
<img src="img.jpg">
$ kawa --output-format xhtml
#|kawa:1|# (html:img src:"img.jpg")
<img xmlns="" src="img.jpg" />
$ kawa --output-format xml
#|kawa:1|# (html:img src:"img.jpg")
<img xmlns="" src="img.jpg"></img>

And here is the default scheme formatting:

$ kawa
#|kawa:1|# (html:img src:"img.jpg")
({}img src: img.jpg )

Procedure: as-xml value

Return a value (or multiple values) that when printed will print value in XML syntax.

(require 'xml)
(as-xml (make-element 'p "Some " (make-element 'em "text") "."))

prints <p>Some <em>text</em>.</p>.

Procedure: unescaped-data data

Creates a special value which causes data to be printed, as is, without normal escaping. For example, when the output format is XML, then printing "<?xml?>" prints as ‘&lt;?xml?&gt;’, but (unescaped-data "<?xml?>") prints as ‘<?xml?>’.