|
That does not seem to be to be typical XML, and if it is, it's really being stretched to do something it's not intended to do, IMO. XML's strength is in representing tree-based structures, but that appears to be an attempt to represent an associative structure. With Sexps, this is just as easy: (sizes (dress . 5) (pants . 7) (shoes . 11))
But in doing that, the structure really looks off, even though it's almost exactly mirroring the XML. I think this is a clue that the XML is a bit of a stretch. Much better (in Lisp code) is: (let ((sizes '((dress . 5) (pants . 7) (shoes . 11))))
; do something with sizes
...)
But I guess the real question is what this is trying to represent. If it's the sizes of various people, then the Sexps are quite simple: (sizes
(sally (dress . 5) (pants . 7) (shoes . 11))
(suzy ...)
(alice ...)
...)
Of course, this could be expressed in XML, but how to do it best? <sizes name='sally' dress='5' pants='7' shoes='11' />
<sizes name='suzy' ... />
<sizes name='alice' ... />
But then perhaps all these sizes should be wrapped in another tag: <sizes-list>
<sizes name='sally' dress='5' pants='7' shoes='11' />
<sizes name='suzy' ... />
<sizes name='alice' ... />
...
</sizes-list>
But now we're getting away from the structure we defined using S-expressions, and besides, name='...' seems to be distinctly different information from the sizes themselves, so something else is strange. Perhaps <sizes>
<sally dress='5' pants='7' shoes='11' />
<suzy ... />
<alice ... />
...
</sizes>
Well, that looks nice, and closer to what we are trying to represent, but of course it's impossible to validate (at least from what I know of XML), since the person names are not part of our schema. We'll have to do something like: <sizes>
<person name='sally'>
<dress size='5' />
<pants size='7' />
<shoes size='11' />
</person>
<person name='suzy'>
...
</person>
<person name='alice'>
...
</person>
...
</sizes>
But now we have the problem of having to place every type of clothing in our schema. We better change it some more <sizes>
<person name='sally'>
<clothing type='dress' size='5' />
<clothing type='pants' size='7' />
<clothing type='shoes' size='11' />
</person>
<person name='suzy'>
...
</person>
<person name='alice'>
...
</person>
...
</sizes>
Great! Now we have something that matches our desired structure and is easy to validate. Of course, it's much more verbose, but that made it easier to read and write, right?Part of the problem with XML is that it causes these huge debates about how to structure and name the data. Another problem is that attributes don't nest nicely; that was the main problem in this instance. In other words, XML can be used nicely to represent a tree structure and reasonably well for lists or simple associative structures. But as soon as those associative elements need to map to something more complicated, you start having issues with how best to structure everything. With S-expressions easily able to express assoc-lists while also being trivially nestable, these issues don't come up. |
It's fairly typical of the XML I've used, and well within what XML was intended to do. That some (many?) people end up with needlessly verbose markup is not the fault of XML. Some people write verbose Scheme. Go figure.
A major point of XML is just simply tree data, but meta-data. You first showed a basic, non-annotated list; I showed a list with meta-data. Seems that you didn't like how the s-exp version of that XML looked, so you changed that use case.
"But in doing that, the structure really looks off, even though it's almost exactly mirroring the XML. I think this is a clue that the XML is a bit of a stretch. "
Or just maybe it's an example where XML differs from s-exps.
"Part of the problem with XML is that it causes these huge debates about how to structure and name the data."
Not really. I mean, some people like that stuff (I see it as a bike shed thing; it's a chance to show off how complex people can make something), but many other folks find a sparse, good-enough structure and move on. Quite honestly, the way you exaggerated the initial example is pure strawman. And you can have the same arguments about representation using s-expressions.
Don't blame a syntax because it allows people to be dopey.
I can see how nicely s-exp can work for markup, but I'm still curious how name-spaces, schema, ID + IDREF, transclusion, and other XML features are handled in s-expressions.
I mostly get the feeling that the only real gripe about XML is the duplication in the closing tags. (The W3C has explained why they dropped the short-form of XML and went with explicit end tags.)