

Using s-expressions instead of XML - jazzdev
http://blog.fandle.com/2010/02/using-s-expressions-instead-of-xml.html

======
ch
I'll just leave this here: <http://okmij.org/ftp/Scheme/xml.html>

~~~
csmeder
It is still cool that he came up with this on his own.

~~~
zitterbewegung
Yea although he goes a little further with scheme.

------
loup-vaillant
To simplify things a bit, I would suggest the use of angle brackets instead of
parentheses:

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

~~~
wingo
Close is not enough -- part of the attraction of s-expressions is that they
are part of the language.

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%...](http://validator.w3.org/check?uri=http%3A%2F%2Fwingolog.org%2F&charset=%28detect+automatically%29&doctype=Inline&group=0))

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/>

------
vdm
XML is not S-Expressions <http://www.prescod.net/xml/sexprs.html>

------
uriel
Nice!

And a good time to remember Erik Naggum's epic S-exps vs. XML rant:

<http://harmful.cat-v.org/software/xml/s-exp_vs_XML>

~~~
dschobel
_Robbery is not just another way of making a living, rape is not just another
way of satisfying basic human needs, torture is not just another way of
interrogation. And XML is not just another way of writing S-exps. There are
some things in life that you do not do if you want to be a moral being and
feel proud of what you have accomplished._

It distresses me that someone could type that up and think it reasonable and
worth sharing.

~~~
gloob
If you find that so distressing, I wonder how you feel about this little
tidbit from Swift:

    
    
      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.

~~~
dschobel
To compare one of the greatest works of satire with Eric's vitriol belies a
fundamental ignorance or insincerity.

What Eric wrote is puerile condescending crap.

But please, quote me an ironic passage of Shakespeare to reiterate Mr.
Naggum's subtle genius.

~~~
gloob
_To compare one of the greatest works of satire with Eric's vitriol belies a
fundamental ignorance or insincerity._

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.

------
mojuba
Can you easily filter raw text out of a Sexp stream? I don't think so. It
would require a full Sexp machine to read and "understand" the tree, whereas
with markup-style data streams it takes a trivial regexp to extract text. (Why
would you need this? Search/indexing, for example.)

~~~
anamax
An "sexp machine" is fairly simple.

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.

~~~
mojuba
With XML or any markup you can ignore the hierarchy and easily strip out
everything that's not text, while with Sexp's I'm afraid you can't. In order
to extract raw text (or actually strings) from SXML you'd need to read and
understand the tree structure, which is not possible with a single-regex run.

~~~
anamax
Oh really?

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 ?

