Summary
A large number of AJAX applications expect that the data exchange between the web server and the browser will be formatted as XML. If the server-side data is stored in an SQL database, you can use a server-side script to transform the tabular SQL format returned by an SQL query into an XML document, or use the XML functionality embedded in your database server to reduce server resource utilization.
The server-side script might be your only option if your database server lacks the required XML functionality (for example, MySQL cannot return query results in XML format), or if you have to perform extensive additional data processing on the SQL results. In any case, you shouldn’t generate the XML output by writing individual tags and attributes to the output data stream, because you might eventually forget one (or more) of the XML encoding rules and therefore produce invalid XML documents; for example, you might forget to encode the ampersand (&) character in the attribute values. It’s much safer to use the DOM functions available in most server-side scripting languages, build a DOM tree with the script, and output the XML representation of the DOM tree as provided by the DOM library.
If your database server supports XML output of query results, but you have to perform specialized data processing to get the XML structure you need to return to the AJAX client, consider server-side XSLT transformations. This technique might be faster than using server-side scripts, even with the added overhead of additional XML parsing.