XML and The Dynamic Contents Approach - Part I
Nowaday, XML technology is growing rapidly because of its capabilities. Well, I am not going to name them all its advantages rather, I would like to concentrate on showing you how to build a dynamic contents using XML acts as a database like. Er!!! what do I mean by that? here is one scenario that we could look at...
Say you are developing a website for an online news company say cnn.com for instance. As you know, this website update frequently sometimes more than once/twice a day...yup, the articles are changing and the contents need to be updated regularly. However, the good thing is the presentation of the website pretty much remains the same. By the way, your boss also would like to keep all the old articles for future reference as well.
From the requirements above, a number of tasks that we must perform, those are:
Design webpage and specify a hot spot
For example, we have designed the welcome page for our website as shown below:
From the design above, we expect to display the three latest articles (from our XML database). Each article, we will show:
If you are still unclear, click here to view the expected output.
Build XML database
Okay, you have seen the end result of that you wish to get, it certainly does help a lot in designing the database, right!.
For sure, what we want is a simple XML database but do the job. We can design skeleton of our XML database (articles.xml) like so:
Click here to view an XML database with some records...Of course, you might want to have a different database design to suit your requirements.
Build the script to pull out the data and display them in the specified hot spot
As you have seen the end result above, the three latest articles that extracted from XML database are shown properly. The best way to achieve it is simply write an ASP script (script.asp) to manipulate the three records out from XML database.
Once we have the script working fine, we now can embed this script - by referencing - into the template welcome.asp above.
<!-- #include file="script.asp" -->
Important: Make sure embed the line above at the specified hot spot, or else the result might not look like we have expected.
Download the source code!
|Copyright © Vovisoft October 2001-2002|