Filename extension | .sxml,.scm |
---|---|
Type code | TEXT |
Type of format | markup language |
SXML is an alternative syntax for writingXML data (more precisely,XML Infosets[1]) asS-expressions, to facilitate working with XML data inLisp andScheme. An associated suite of tools[which?] implementsXPath,SAX andXSLT for SXML in Scheme[2][3] and are available in theGNU Guile implementation of that language.
Textual correspondence between SXML and XML for a sample XML snippet is shown below:
XML | SXML |
---|---|
<tagattr1="value1"attr2="value2"><nested>Textnode</nested><empty/></tag> | (tag(@(attr1"value1")(attr2"value2"))(nested"Text node")(empty)) |
Compared to other alternative representations for XML and its associated languages, SXML has the benefit of being directly parsable by existing Scheme implementations. The associated tools and documentation were praised in many respects by David Mertz in his IBM developerWorks column, though he also criticized the preliminary nature of its documentation and system.[4]
Take the following simpleXHTML page:
<htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en"><head><title>An example page</title></head><body><h1id="greeting">Hi, there!</h1><p>This is just an ">>example<<" to show XHTML& SXML.</p></body></html>
After translating it to SXML, the same page now looks like this:
(*TOP*(@(*NAMESPACES*(x"http://www.w3.org/1999/xhtml")))(x:html(@(xml:lang"en")(lang"en"))(x:head(x:title"An example page"))(x:body(x:h1(@(id"greeting"))"Hi, there")(x:p"This is just an \">>example<<\" to show XHTML & SXML."))))
Each element's tag pair is replaced by a set of parentheses. The tag's name is not repeated at the end, it is simply the first symbol in the list. The element's contents follow, which are either elements themselves or strings. There is no special syntax required for XML attributes. In SXML they are simply represented as just another node, which has the special name of@
. This can't cause a name clash with an actual"@"
tag, because@
is not allowed as a tag name in XML. This is a common pattern in SXML: anytime a tag is used to indicate a special status or something that is not possible in XML, a name is used that does not constitute a valid XML identifier.
In SXML strings there are two characters that must be escaped, the"
string delimiter (with\"
) and the\
escape symbol itself (with\\
). The XML code above requires escaping three:&
,<
and>
(with&
,<
and>
respectively).