I've always made the second part of your argument: that namespaces are the key feature that make XML useful, especially for the eXtensibility in XMPP. I also think that namespaces are a part of XML that few people understand, partially because many XML/XMPP implementations don't even (fully/correctly) support them.
The rest of what you say is new though! The solid examples you gave for compactness/ordering were impressively concise.
I'd even go further and say they generally illustrate the difficult readability that can arise in JSON with not-so-difficult requirements--I had more trouble following the JSON than the XML here, by far. I'd say the embedded comments and possibility of a schema in XML are also a bonus, to help understand the meaning if it isn't obvious.
I am by no means an XML-supremicist, but I do take the unpopular view that it is a much more future-proof and natural solution for many more use-cases than it gets credit for. I'd love to see a successor that cuts out some of the warts as much as the next person, but every solution has pros/cons, and XML is a pretty good balance in a lot of cases where people refuse to look at it.
This turns into this beautiful JSON:
[
"users": [
{
"id": "abc",
"phoneNos": [
{ "type": "home", "value": "123456789" },
{ "type": "work", "value": "321654987" }
]
}
]
]
------ ... endquote.That's a strange, contrived example. In Javascript, I would write it like this:
user = {id: "abc", homePhone: "123456789", workPhone: "321654987"};
(And the next time that object goes across the network, my libraries will be nice enough to put the quotes around the keys for me.)
Anyway just imagine there’s an extra field, problem solved:
<phoneNo type="home" priority="1">…</phoneNo>EDIT:
> Maybe we need jQuery for XML?
Adding more layers of complexity to deal with complexity? I am further convinced that XML is bloated and bureaucratic. I am so happy that modern browsers let met get away from jQuery. Plain, vanilla JS is better for the soul.
The X in XMPP stands for extensible not XML. The reason XML fits the bill is because it has concept of namespaces, what JSON has? If you don’t have explicit namespace support how do you make your JSON variant of XMPP forward‐compatible? You don’t without making it look much, much, worse than any of the examples I’m about to show below.
> (…) I really do prefer JSON over XML because of how compact and readable it is.
> XML is big, bloated, and bureaucratic.
My standard response to this is always “show me a JSON fragment that is shorter or prettier looking than an equivalent XML fragment.”
XML can certainly be shorter than JSON and often is, and repeated tags are the best showcase for it:
This turns into this beautiful JSON: Oh, but what if order is important? Take this example: Now you have to do it like that: For an example of how horrible JSON in wild can really be see Reddit’s JSON API. Because JSON has no syntax for metadata you get things like that: See the keys are sorted for convenience.XML’s text representation is very minimal and consistent. You don’t need to quote Every Single Thing, and there are no special cases for not quoting just some type of values. The only redundant part of XML is repeating the name of the closing tag if the </element> has value. But this actually aids readability, as demonstrated above.
Editing complex JSON by hand with a regular text editor is a nightmare, because of all those single '}', ']' and commas trailing for several lines when there’s any light nesting involved. Editing XML by hand on the other hand is no big deal.