Posted on ::
Legacy

A blast from the past... In the last century, when we wrote XML by hand, I designed a format to get rid of one of XML multiple annoyances: as it used ordinary characters as deleimters, such as <, >, &, it means often quoting hell.

The idea: Use non-ascii-7bits characters as markup!

  • Use «foo» to delimit tags, instead of <foo></foo>
  • Use these regular elements as escape sequences instead of entities. Escape « by «-». Not really readable — but more than entities — but natural and consistent to parse.

I wrote the KXF <-> XML converter in Klone, my lisp scripting language, that I definitely need to publish here as part of these legacy series.

Here is the doc of the format:

KXF: The Koala XML Form

Purpose

The Koala XML Form XML avatar has been defined with the following design goals:
  • Ease writing by hand
  • Ease human readability
  • Solve only syntaxic problems
    • no entities
    • no DTD
    • no CDATA
    • straightforward whitespace handling
    • get rid of most quoting hell: use less special chars, and use non ascii ones

Design

Here are some examples:

KXFXML
«tag»<tag/>
«tag foo <> bar»<tag>foo &lt; &gt; bar</tag>
«tag(x=y z="1 2" t='gp') gee»<tag x='y' y='1 2' t='gp'>gee</tag>
«! comments»<!-- comments -->
«? PIs»<?PIs?>

Quoting special chars:

CharQuoted formWhere
««-»character data contents
»«+»character data contents
'«!»attribute values
'«/»attribute values
"«#»attribute values
"«*»attribute values
  • »«/tag» optional ending forms can be used to check nesting as in
    «foo a very big contents... »«/foo»
    • ending contents is ignored and can be used for comments, as in:
      «foo a very big contents... »«/foo the main loop»
    • attributes if present must match the starting tag attributes:
      «foo(x=1) a very big contents... »«/foo(x=1)» matches, but
      «foo a very big contents... »«/foo(x=2)» raises an error
  • Whitespace around sub-elements are discarded, but not around character data.
    You can keep them by postfixing element name with = (it sets the xml:space attribute to "preserve"), such as
    «pre=(a=b) «b x» «i y»» or by enclosing them in the pseudo node «= »
    «x «= » «y» «z»» keeps space before y, but not between y and z
  • For comfortable use, it is recommended to assign «» to shift-keypad-minus and shift-keypad-plus respectively
  • Encodings are raw: either ISO-Latin-1, or UCS2, which can be autodetected as fields must begin with «<letter> (ISO-Latin-1), \0« (UCS2), «\0 (MS UCS2)

Benefits

  • More readable
  • Most text editors know how to balance « and » better than <foo> and </foo>
  • It is self sufficient: whitespace handling is explicit
  • No need to quote the common chars <, >, &

Drawbacks

  • You cannot use XML Tools on this format. Not really a problem, as you can convert to and from XML

Tools

For now, there exists only a parser/writer in Klone (xml-ksf.kl, used to implement Klone scripts (xml2kxf, kxf2xml) that converts back and forth to XML.

A java SAX parser is planned

Author

Colas Nahaboo
Back to XML Avatars