Working with XML and HTML

Kawa has a number of experimental features for working with XML. These are built on the concepts of the gnu.lists package.

Scheme functions

Function: make-element tag [attribute ...] child ...

Create a representation of a XML element, corresponding to

<tag attribute...>child...</tag>

The result is a TreeList, though if the result context is a consumer the result is instead "written" to the consumer. Thus nested calls to make-element only result in a single TreeList. More generally, whether an attribute or child is includded by copying or by reference is (for now) undefined. The tag should currently be a symbol, though in the future it should be a qualified name. An attribute is typically a call to make-attribute, but it can be any attribute-valued expression.

(make-element 'p
	      "The time is now: "
	      (make-element 'code (make <java.util.Date>)))

Function: make-attribute name value...

Create an "attribute", which is a name-value pair. For now, name should be a symbol

Function: 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>.

xquery language

W3C is working an an XML Query language, and a draft has been released. If you start Kawa with the --xquery it selects the "XQuery" source language; this also prints output using XML syntax. See the Qexo (Kawa-XQuery) home page for examples and more information.

XSL transformations

There is an experimental implementation of the XSLT (XML Stylesheet Language Transformations) language. Selecting --xslt at the Kawa command line will parse a source file according to the syntax on an XSLT stylesheet. See the Kawa-XSLT page for more information.