The senior architects in my company think that APIs that use XML as data interchange format are better and easy to manage. Do you think XML APIs have any real benefits today? Isn't JSON a better data interchange format? Which one according to you is better?
P.S. If you say use the right tool for the right job, I would like you to mention the areas in which each one excels.
XML has mature tooling, and soap in particular is more thoroughly defined. Those are the biggest advantages of XML.
I actually consider the fact that XML is more expressive than the languages used to interact with it a disadvantage. XML has both attributes and children.. And it takes a definition file to know the intended difference. JSON can be mapped to clear objects more easily, even without secondary documentation.
When you're dealing with a foreign service, clear examples of calling a json service with curl are often more clear than wsdl output. And json is much smaller in payload size.
Where soap/XML shine is where you're using complementary tooling for you client and server... Either Java at both ends, or .Net. However, when your consumer is another language there is often a disconnect. Beyond this, if you're using the same tooling, like wcf, you can use json as the transport layer anyway, gaining a much smaller footprint.
Most modern service tooling on the server can mount both JSON and XML end points.. I'd say do both if you can... Otherwise JSON with clear documentation is better.
XML has much better tooling (XSD, XSLT, xpath, etc.) but looks ugly and does not mix well with modern front-end technology which is all Javascript based. So I would go with JSON.
as @JanVladimirMostert says, XML is more descriptive. If you need annotated data, XML is more practical (ex: list of movies with cast). Similarly, if you need highly nomenclature-d data, XML is better (e.g, defining node types and what they can or can't have as properties is easier in a DTD). If size is an issue, or if you want higher compatibility (XML parsers can differ, JSON parsers not so much), go for JSON.
So in summary I'd agree with the senior architects of your company that it is "better as a data interchange format", in the strict sense that XML conveys more meaning than JSON (after all the whole purpose of the -ML family was to semantically annotate data). As for which is better in a vacuum, it's a bit of a meaningless point. You could also go with URL-encoded strings, or your own custom format. If, say, the data you need to send is "user logged in" or "user logged out", you could go with an 8-bit identifier with a 1 bit flag. It all depends on the purpose of whatever data you're exchanging.
I'd say in the end it's about convenience. I haven't used XML in years because I have no particular use for it, and since I'm basked in JS most of my day,. Json is one JSON.parse() away. If I was using a framework with XML baked-in or part of the stdlib, I'd use XML instead.
Alpha Geek
Alpha Geek
Xananax
XML is more descriptive and easier to read, JSON is smaller, so uses less bandwidth to pass around.
Which one is easier to read?
<animals> <dog name="superdog"> <legs>4</legs> <eyes>2</eyes> </dog> <cat name="catman"> <legs>4</legs> <eyes>2</eyes> </cat> <pig name="superpig"> <legs>4</legs> <eyes>2</eyes> </pig> <cow name="supercow"> <legs>4</legs> <eyes>2</eyes> </cow> <mutant name="xman"> <legs>8</legs> <eyes>16</eyes> </mutant> </animals>VS
{ "animals": [{ "type": "dog", "name": "superdog", "properties": [{ "legs": 4 }, { "eyes": 2 }] }, { "type": "cat", "name": "catman", "properties": [{ "legs": 4 }, { "eyes": 2 }] }, { "type": "pig", "name": "superpig", "properties": [{ "legs": 4 }, { "eyes": 2 }] }, { "type": "cow", "name": "supercow", "properties": [{ "legs": 4 }, { "eyes": 2 }] }, { "type": "mutant", "name": "xman", "properties": [{ "legs": 8 }, { "eyes": 16 }] }] }I personally think the XML reads easier, especially when going many layers of nested properties deep, but I'd rather send JSON over the wire.
If small message size is what you're looking for, rather go for something binary like Message Pack and when you need to display it somewhere, display it in XML.
The Message Pack equivalent in HEX would be: