XML (and DOM) vs JSON

The main problem with XML is that it is being abused, by unexperienced programmers, for applications where it is not suited (XML is designed for document text markup) like general data structures serialization (like SOAP where formats like JSON are much more suited) and persistence (where a RDBMS like a SQL database is much more suited).

XML is OK as markup for text documents, but it is not suited as a data serialization format.

In my honest opinion, XML should always be created and accessed through DOM. I have seen lots of software creating XML documents not using DOM and thus making huge mistakes like malformedness, incorrect escaping and even making the data serialized to XML not being the same as the data deserialized from that XML. Take a look at this tutorial to generate XML with DOM otherwise you may perform these XHTML common errors.

The biggest mistake made with XML was making it a text file format by default instead of a binary format. If it was made a binary format everyone would always use DOM to access and modify it both from client and server applications (exiting templates using a XML editor) and many of the mistakes developers make today would not me made.

I have found that for data structures serialization JSON (or its sibling YAML, as used in Google App Engine) is much more suitable than XML, because accessing a list hash and scalar data hierarchy is easier than accessing data from XML DOM. I totally agree with Kris Zyp - XML vs JSON.

Anyway, for maximum efficiency and speed you need to use ASN.1 DER or a less standard but maybe with even more future like Google's Protocol Buffers (see what Google has to say about the inefficiency of XML).

What is the worst abuse of XML that you have seen?

No comments: