Why use xml with ajax

Continuing with my explorations of ajax, I was struck with the question of why to use xml as the message structure. It seems that there are two options.

    Use javascript to add functionality to the page, use xml as transport from the server, format response and alter page.
    Use javascript to add functionality to the page, use html as transport from the server, directly embed response to alter the page.

The main difference here is that the conversion of the xml response from the server into a something that can be displayed on the page is actually a rather tricky matter. I think that that’s where the javascript functions are getting incredibly complicated and breaking for developers. Handling errors in xml parsing and formatting is a PITA. It requires a LOT more of the display logic to reside with the client.

Why not just have the server handle all of that and keep the client a bit dumb and just insert whatever it gets back from the server using element.innerHTML method. This makes development of ajax apps 1000% easier.

The downside of course is that it’s more difficult for other apps to work with the interfaces. If this is something that you want to do with your application, you should probably be looking to expose interfaces explicitly for this purpose. This will allow for monitoring and control of these interactions. Once you’re doing the formatting for html, it’s not that much harder to add a second one for xml on the server side.