Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would you use XML over JSON for Ajax?

Tags:

ajax

xml

Recently, many programmers and that includes me, have taken the X out of AJAX, and by default use JSON as the protocol format. However I'm trying to think of some places where XML would be more appropriate as a protocol format, that doesn't include SOAP (because SOAP could theoretically be done with JSON anyways).

Note: I love me XML for many other purposes, so its not about XML vs JSON in general, I'm concerned in particular with AJAX's transmission protocol.

like image 466
Robert Gould Avatar asked Jan 26 '09 04:01

Robert Gould


1 Answers

This question is very similar to When to prefer JSON over XML?

Anyhow, I agree with the top voted answer there:

I use JSON unless I'm required to use XML. It's simpler to understand, and (because it requires less configuration overhead) easier to program for reading and writing if the libraries are available in your context, and they're pretty ubiquitous now.

When Amazon first exposed their catalogs as a web service, they offered both JSON and XML. Something like 90% of the implementers chose JSON.

On the flip side of things, XML is good for situations in which...

  • You need message validation
  • You're using XSLT
  • Your messages include a lot of marked-up text
  • You need to interoperate with environments that don't support JSON
  • You need attributes or namespacing

This is also taken from the question above, which is essentially asking the opposite of this.

like image 102
Paolo Bergantino Avatar answered Oct 20 '22 00:10

Paolo Bergantino