Using s-expressions instead of XML
blog.fandle.com
blog.fandle.com
<tagname <@ attr "value" attr2 "value2">
<tagname2>
<tagname3 "data">>
Going a bit further, we could require the `@`, and place it after the attributes list. This format has fewer special cases: <tagname attr "value" attr2 "value2" @
<tagname2 @>
<tagname3 @"data">>
Finally, we could remove the quotes around the raw strings ("data"), while inverting the brackets: >tagname attr "value" attr2 "value2" @
>tagname2 @<
>tagname3 @data<<
This may look twisted, but we stay very close to true S-expressions, while using the same escape characters we have in plain XML.Thus you can use the language's escaping mechanisms, or put the escaping in your sxml->xml filter.
Preserving XML escapes is not actually a virtue. If you enter your data using S-expressions and validate on transformation, you will never have malformed XML.
(Not in any way that matters, anyway: http://validator.w3.org/check?uri=http%3A%2F%2Fwingolog.org%...)
edit: note also that in this context, s-expressions are more about language and less about parentheses; one can have them in python too: http://wingolog.org/pub/original/rename-to-index.py.txt, http://wingolog.org/software/original/
To give an example of why this is powerful, suppose I decide I need two different namespace of attributes. In your example, this is hard. I can either do:
>tagname attr "value" @ attr "value2" !<
which special cases the parsing, and is hard to understand, or >tagname ns1:attr "value" ns2:attr "value2" @<
which makes it hard to process attributes (xml is like this)Sexps have an easy, obvious solution
(tagname (@ attr "value") (@other attr "value2"))
which I'd argue is clearer, more backward compatible, and doesn't require changing the parser.Now this is only one example, but the point of sexps is they don't have an special cases, and they move the semantics out of the syntax and into the processing.
And a good time to remember Erik Naggum's epic S-exps vs. XML rant:
It distresses me that someone could type that up and think it reasonable and worth sharing.
I have been assured by a very knowing American of my
acquaintance in London, that a young healthy child well
nursed, is, at a year old, a most delicious nourishing and
wholesome food, whether stewed, roasted, baked, or boiled;
and I make no doubt that it will equally serve in a
fricasie, or a ragoust.
There are types of writing that do not revolve around literally and bluntly saying what you mean. I rather doubt that Mr. Naggum actually believes that XML is morally comparable to rape, in much the same way that I rather doubt Mr. Swift was seriously arguing that the Irish should begin eating their children.What Eric wrote is puerile condescending crap.
But please, quote me an ironic passage of Shakespeare to reiterate Mr. Naggum's subtle genius.
I would hope neither, obviously, though it's entirely possible I'm wrong. I would rather just discuss the writer's actual point rather than his stylistic decisions or personality flaws.
You will be recognized as a genius when you make insightful arguments others can follow and which teach them something; not when you require them to wade through a pile of irrelevant drivel, as if it was a high school exercise in summarising.
Erik doesn't even make arguments. He just states things, like
Remove the syntactic mess that is attributes.
(You will then find that you do not need them at all.)
Yeah, that's a really solid argument, that immediately convinced me that seperating syntactically between metadata elements and child data elements is not necessary...And yes, you can use regexs on s-expressions in exactly the same way that you'd use them on xml/html/markup. And you'd run into the same errors.
Note that reading s-expressions and extracting things from the result is significantly easier and faster than using regexs.... (The same is true of xml.)
Regular expressions are a great hammer, but many things are not nails.
How do you know that the sequence of bytes http://foo.bar.com/a/c is text or an attribute value with a regexp? How about foo.bar? How about Times Roman or 16px? How about the four bytes html ?