Search This Blog

Sunday, September 30, 2007

Serve SQL Data in XML Format

Quite often, the data you have to serve to the client will reside in
SQL databases on the server, so you need an adapter between the tabular
binary SQL data and text-oriented hierarchical XML data. This article,
describes a few ways to extract data from SQL databases and serve it
to an AJAX application running in a web browser, depending on the SQL
database you use and the implementation flexibility you need. 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. More Information

No comments: