Lx: a compact syntax for XML (or, sexp-to-SAX in Java)

Version @VERSION@, released @RELEASEDATE@



XML's many virtues do not include conciseness. This is generally not a problem, but in cases where there is more markup than text -- such as an XSLT transformation script or a set of RDF statements -- it can be difficult to see the important content of a document behind the forest of angle-brackets and closing tags.

Lx provides an alternative for just this situation. These Java classes define a compact syntax for XML, and an implementation of the SAX XMLReader which turns it into a stream of SAX events.

Another way of looking at this is that Lx provides a notation for XML in lisp-style sexps, similar in some ways to SXML, though that's mostly concerned with going the other way. Or, put yet another way, this is a sexp-to-SAX converter in Java.

Here's the XSLT identity transformation:

;; The XSLT identity transformation
(lx:namespace ((#f "http://www.w3.org/1999/XSL/Transform"))
  (stylesheet version: 1.0
    (template match: "node()|@*"
        (apply-templates select: "@*|node()")))))

This is pure XSLT, and would be accepted as such by any XSL transformation engine which allows you to plug in an alternative parser. It's trivially easy, for example, to have Saxon use stylesheets written in Lx syntax:

% CLASSPATH=.../saxon8.jar:.../lx.jar
% java net.sf.saxon.Transform \
       -y uk.me.nxg.lx.reader.LxReader \
       input.xml script.lx

See the javadocs for more examples of use.

The (lx:namespace ...) structure maps the null prefix to the XSLT namespace within its scope. Elements are indicated with an open parenthesis followed by the element name, and stretch to the matching parenthesis. Attributes are indicated by the attribute name plus a colon, then the attribute value.


Full documentation is in the package javadocs. There are also distributed examples.

Source, downloading, building and licensing

The source is available to browse and checkout at code.nxg.name.

The binary and source downloads are available to download here: at source, and at binary.

If you wish to build the package from scratch, download the source distribution, and build it with ant build.


The package is Copyright 2003-2012 Norman Gray, and is released under the terms of the GNU General Public Licence (though contact me if you have other licensing requirements).


0.5.3, 2012 August 5
0.5.2, 2008 August 7
Fix tokeniser bug.
0.5.1, 2008 May 4
Various documentation improvements
0.5, 2007 May 9
0.4, 2005 November 7
0.3, 2004 May 12
Strings "..." now preferred over [...], and now allow newlines and escapes
0.2-1, 2004 April 21
Documentation improvements
0.2, 2004 April 18
First public release