So there's a ton of utterly crap XML applications out there with no rhyme or reason, and these crap XML enterprise apps are most developer's understanding of "real world XML". Similar to how terrible C++ code being all over the place is making people hate C++ the language.
-------
XML can be used very well however: its use in Jabber / XMPP is clear and concise. XML Namespaces are needed due to the extensions of XMPP, and various programs can interact with the protocol. Specifications are clear, the ability to "stream" data is proven, different parser strategies have been implemented. Its clear that XML in this instance works, and works pretty well.
I mean if there's enough of it, it kinda becomes "real world XML". Right or wrong human's ability to actually use the tool or tech well is often where the bar is set. Could be a great idea but if folks can't do it... won't fly.
I can't count how often I've seen XML that looked like this:
<container name="containerName">
<attribute name="attrib1" value="value1" />
<attribute name="attrib2" value="value2" />
<attribute name="listAttibute" value="pipe|delimited|values" />
<attribute name="containedAttribute" value="<container name="otherContainer"..." />
...
</container>
Which was, technically, XML (it even conformed to a schema!)... almost like "malicious compliance".It's also highly redundant (so it basically can't be hand written), undesrpecified (do I put this value as an atribute, value, or sub-element?), underpowered (how does it represent numbers? Byte streams?), complicated (have you ever created a DTD by hand?), and just out badly designed.
Of course, JSON and YAML share some of those same problems, and add some different ones. But the complaints about XML aren't some superfluous opinions about how it looks.
Oh there are lots of ways to beat XML into looking like it can do it but they’re all bad, break all the actual semantics of XML and turn a nice deserialization story of a tree where each node is a complete thing into mess.
Turns out that very few people actually needed a tree of heterogeneous string k-v pairs.
For comparison, time formats in JSON are all over the place.
I think that's the main problem of XML it's not meant to be read by humans but people thought it was.
So you have an already complex document parser (which you are using only a fraction of the full functionality!) with the added complexity of a schema system layered on top. This is why JSON took off so fast, it ditched the whole document part and just gave you the data.
<items>
<item id="1" attr1="value 1" attr2="value 2" attr3="value 3" />
<item id="2" attr1="value 1" attr2="value 2" attr3="value 3" />
<item id="3" attr1="value 1" attr2="value 2" attr3="value 3" />
<item id="4" attr1="value 1" attr2="value 2" attr3="value 3" />
<item id="5" attr1="value 1" attr2="value 2" attr3="value 3" />
</item>
It's not something that an IBM committee would have come up with but it fits the needs of an application. If XML has an "intrinsic fault" it's related to DTDs and namespaces which allow for the creation of horrible, complex monstrosities. XML can be every bit as stripped down and to-the-point as JSON, trading the curley braces for angle brackets. JSON's best point is that it doesn't support any of this needless complexity but it's still easy enough, with enough nested objects and arrays, to make something that's effectively not readable by a human.Items can be order-dependent in XML. So the "id=1" thing is still superfluous. See xs:sequence. (In contrast: xs:all declares something to be order independent).
If you were doing XML for your own apps, I think xs:sequence items simplify parsing grossly.
Ex: if you have Address, maybe you always want "Street", then "Zip Code", then "State".
<Address>
<Street> 1234 Blah Street </Street>
<City> Springfield </City>
<State> Whatever </State>
<Zip> 55555 </Zip>
</Address>
By declaring that Street -> City -> State -> Zip must happen in that particular order, you can grossly simplify the parser's job when reading such data in. (Or writing it out).--------
If there are multiple People at this address, you could (and probably should) just list them out in order.
<Address>
<Street> 1234 Blah Street </Street>
<City> Springfield </City>
<State> Whatever </State>
<Zip> 55555 </Zip>
<People>
<p> Marge </p>
<p> Homer </p>
<p> Lisa </p>
<p> Bart </p>
<p> Maggie </p>
</People>
</Address>In XML, there was always some motherfucker trying to stuff CSV into an attribute.
And the difference between ID as specified and ID as implemented lead to a lot of problems, reaching its zenith (or maybe nadir?) in the XML Signature spec.
If you need three values use an array (or in xml, child element)