Before you start
Figure 1 illustrates the development of the IOD Planner application. All loading is done in the background to avoid the refresh lag, and rich widgets are used for form fields, dialog boxes, and drop-down menus.
Figure 1. IOD Planner 2006
You should be reasonably familiar with Web development and databases. The tutorial "DB2 XML evaluation guide" (developerWorks, June 2006) gives an excellent introduction to DB2 9, while "Query DB2 XML Data with XQuery" (developerWorks, April 2006) does the same for XQuery.
To deploy the source code, you will need a Windows or Linux operating system. On it, you will need Zend Core for IBM (see Resources for a download link). Zend Core conveniently bundles the DB2 9 Express-C data server, Apache2 Web server, PHP scripting language, DB2 extensions for PHP, and a powerful administration console.
Figure 2. Traditional Web model and Ajax model
The key tenet of the Ajax philosophy is to avoid loading new Web pages. Instead, you load new content in the background and then show it within the existing page. This avoids the wasteful reloading of basic infrastructure and the frustration of waiting for the browser to render the same navigation and design. Your users never see a blank, loading screen. The final effect is that of a speedy, very responsive application.
Requests to the server are sent using an
XMLHTTPRequest object, and responses are
Major Ajax-style Web applications include Bloglines, Del.icio.us, Digg, Flickr, Google Maps, Gmail, and Reddit.
Dojo has a modular design, with extra functionality loaded on demand.
As the number of contenders in Figure 3 suggests, Dojo is a new field. It's a quickly consolidating one. Both Dojo and Script.aculo.us made large mindshare gains in the past year. Of the two, Dojo has a more robust architecture and greater industry backing.
A relational database back end for a Web application is a given. We've chosen DB2 Express-C, which is a free-to-download, free-to-deploy, and free-to-distribute version of the DB2 9 data server. It also has native XML capabilities, which calls for some elaboration.
Figure 4. Historical ways of combining XML with a relational database
Any sufficiently large enterprise application tends to have XML in it. Often, XML is the most natural form for the data to take. This means that XML is either stored in files, stored wholesale in database CLOBs, or shredded into distinct columns.
Alas, mixing individual XML files with a relational database is hard to scale; XML in CLOBs is hard to query and slow; shredding XML into relational columns means that the relational schemas have to be synchronized with XML schemas -- every change to XML structure triggers expensive regression testing on the whole database.
Figure 5. Native XML in DB2
DB2 9 solves the problem. Its native XML data type is easy to query with SQL and W3C-standard XQuery. It scales with the database, and XML-specific optimizations give it better performance than CLOBs. Finally, it keeps XML and relational schemas separate -- there's no need to regression test everything when you've only changed the XML structure.
Figure 6. XQuery and DB2
XQuery is a W3C standard for querying data from XML files. The
WHERE clauses in XQuery and SQL are similar, and the
FOR loop is intuitive to casual programmers. XQuery code is faster to write, easier to read, and generally friendlier than equivalent XSL.
FLWOR ("flower") is often mentioned in the context of
XQuery. It refers to
ORDER BY, and
RETURN statements, the foundations of XQuery.
For an excellent introduction, please consult the article"Query DB2 XML Data with XQuery."
PHP is a popular and easy-to-learn server-side scripting language. It has a lower learning curve than Java servlets or .NET, while offering the same powerful, advanced features for the experienced professional. As an interpreted scripting language, it is very friendly to iterative development -- there's no recompiling after a single change, and you can see the impact of your code changes in real time.
Needless to say, you should have separate development, testing, and production environments. Live editing is not recommended.
We chose XSL for its powerful transformations. In hindsight, it would have been better to rely exclusively on XQuery. Its facilities are also excellent, and our code would have been shorter and more elegant. XQuery is a friendlier, side-effect-free language tailored for transforming from one XML structure to another. We are already using XQuery to generate well-formed XML, so we could have bypassed the second transformation entirely.