XML as Simple Object

From Zanecorpwiki

Jump to: navigation, search

There's essentially two primary data exchange formats in AJAX: XML and JSON. At the end of the day, they're both so similar functionally that it almost comes down to aesthetics. I slightly prefer XML largely because I work in *a lot* of different languages and theres broad XML support in everything and all XML libraries support processing with pretty much perfectly analogous interface derived from a common meta-level API.

I also like the fact that XML is a data exchange format whereas JSON tries and fails to be an object exchange format. I say "tries and fails" because AFAIK JSON only really works as an object exchange for JavaScript, but that relies on JavaScripts relatively unique rules regarding scope and interpolation. The fact is that in most languages, object exchange is hard and doing common object exchange harder still.

So in reality, JSON is just a data exchange, which is fine, except that in JavaScript it gets confusing and I'm willing to pay the overhead to keep it clear that this incoming packet is data and not an object. Note that this makes JSON great as an object exchange protocol for JavaScript and if I was writing server side code in JavaScript, JSON would be the perfect choice if I didn't care about communicating with non-JavaScript clients.

XML related stuff can get unwieldy, but I find it's pretty easy to stay away from all the complex stuff. In other words, any time you can use JSON, you can use simple XML. And processing simple XML is not any harder than processing JSON. Producing simple XML is not any harder than producing JSON. XML is more verbose, but I also think it's clearer to non-coders for whom the distinction between a curly brace and a square brace isn't immediately obvious.

References

Kibbles Programming Style:Javascript from Dog Food Software (disclaimer: my company); search for 'just use the XML'.

Personal tools