Using XML and Data Islands to Reduce Server Load

 <  Day Day Up  >  

If XML had no purpose except to send tables across the Internet, it would be pretty useful. However, it has additional and unexpected benefits. And others will probably be invented that we haven't yet thought about.

Traditionally, if we wanted to send out an attractive page of tabular data, we wrote a program to do a SELECT from a database, generated HTML with TABLE , TR , and TD tags to format the data with nice colors, and sent it out. That required running the same program each time we wanted to display the table, even if the same query was made many times a day.

What if we could send out a file containing data and formatting instructions, and let the user 's computer do the formatting? We can do that. We have the technology. It's called Data Islands .

Data Islands

Internet Explorer (and probably other browsers as well) support the use of Data Islands, which permit us to output a file containing the instructions for formatting data, and let the user's browser do the work. This is especially attractive because servers have the ability to cache pages as they're served . The next person who requests the same page gets the in-memory copy of the page, which is about a thousand times faster than doing another query and formatting the output.

The HTML page shown in Listing 7.30 contains an example of the use of Data Islands.

Listing 7.30. An HTML Page Containing XML and a Data Island
 <html> <head><title> Example of XML embedded in HTML </title></head> <body> <h2><font color="#FF6633">Example of XML embedded in HTML</font></h2> <XML ID="FantasyIsland"> <clients>  <client>   <first>Juan</first>   <last>Perez</last>  </client>  <client>   <first>Les</first>   <last>Pinter</last>  </client> </clients> </XML> <table DATASRC="#FantasyIsland" border="1" bgcolor="#FFFFFF" cellspacing="2"> <tr><td bgcolor="silver" width="100"><div DATAFLD="first"></div></td>     <td bgcolor="silver" width="200"><div DATAFLD="last"></div></td> </tr> </table> <hr>End </body> </html> 

The resulting Web page is shown in Figure 7.16.

Figure 7.16. Formatting an XML data island with HTML.
graphics/07fig16.jpg

It's easier to read, and more importantly, all of the rendering is done on the browser. If you already have the XML, you can construct pages like this on the fly, pasting the XML into the middle of the output.

 <  Day Day Up  >  


Visual Fox Pro to Visual Basic.NET
Visual FoxPro to Visual Basic .NET
ISBN: 0672326493
EAN: 2147483647
Year: 2004
Pages: 130
Authors: Les Pinter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net