Hacker News new | ask | show | jobs
by cheez 5479 days ago
I think the difference is that XML protocols are meant to be generated while JSON protocols are meant to be hand-written to some extent.

Otherwise, what's the difference with:

{'ret': 'pump me up'}

And

<object> <slot name="ret">pump me up</slot> </object>

If it's a computer generating it?

3 comments

The difference is that in JSON there's pretty much only one way to do it, the way you have there. With XML there's many ways to do it (see examples on this thread). So when using XML, you need to write code adapted to the way it's 'encoded'.
huh? thats not the motivation or intent of either format's design.
Replace "hand-written" and "machine generated" with "human consumption" and "machine consumption"
I think it is the other way around. XML is explicitly designed to be writable and editable by hand, which is also the reason for some of it's syntactic redundancy.
If you think XML is writable, you are a bigger man than me.
You need to understand the initial use case for XML. It was invented for document-oriented markup languages like HTML, MathML, Docbook etc. You can definitely write XHTML by hand, and a JSON-based syntax for the same kind of documents (which mixed content and so on) would be a lot harder to read and write.
My understanding is that XML was derived from document-oriented SGML, to beat SGML into a form that would work well with XSL and XPath.

But I'd like to point out that the way SGML-derived markup distinguishes attributes and child nodes is entirely arbitrary. You could as easily make attributes child nodes - it's all in how you interpret what's written. Likewise, you can "convert" SGML to JSON (or YAML or S-expr or whatever) very easily, bearing in mind that attributes and child nodes sit in the same space with each other - a well-formed XHTML document, for example, can be re-expressed in JSON without ambiguity, since tags have a well-specified, unambiguous list of allowed children and attributes - just give text nodes the name "text" and you're golden.