Fetching XML Data from the Server for an AJAX Headlines System - Creating an XML file for storing data
(Page 4 of 4 )
Admittedly, the headlines application would be rather incomplete if I didn’t show you the corresponding XML file, which is useful for storing, in a well-structured fashion, all the headlines, images and links that will be displayed on the pertinent web page.
Since the XML file in question is requested in the background the first time the web document is loaded, and additionally must be capable of maintaining all the data accommodated in a correct way, below I coded a basic version of it called “headlines.xml.” It can be easily modified to suit more specific requirements. Have a look at it, please:
<?xml version="1.0" encoding="iso-8859-1"?>
<headlines>
<headline>
<image>image1.jpg</image>
<url>Link for headline 1 goes here</url>
<text>Text for headline 1 goes here</text>
</headline>
<headline>
<image>image2.jpg</image>
<url>Link for headline 2 goes here</url>
<text>Text for headline 2 goes here</text>
</headline>
<headline>
<image>image3.jpg</image>
<url>Link for headline 3 goes here</url>
<text>Text for headline 3 goes here</text>
</headline>
<headline>
<image>image4.jpg</image>
<url>Link for headline 4 goes here</url>
<text>Text for headline 4 goes here</text>
</headline>
<headline>
<image>image5.jpg</image>
<url>Link for headline 5 goes here</url>
<text>Text for headline 5 goes here</text>
</headline>
<headline>
<image>image6.jpg</image>
<url>Link for headline 6 goes here</url>
<text>Text for headline 6 goes here</text>
</headline>
<headline>
<image>image7.jpg</image>
<url>Link for headline 7 goes here</url>
<text>Text for headline 7 goes here</text>
</headline>
<headline>
<image>image8.jpg</image>
<url>Link for headline 8 goes here</url>
<text>Text for headline 8 goes here</text>
</headline>
<headline>
<image>image9.jpg</image>
<url>Link for headline 9 goes here</url>
<text>Text for headline 9 goes here</text>
</headline>
<headline>
<image>image10.jpg</image>
<url>Link for headline 10 goes here</url>
<text>Text for headline 10 goes here</text>
</headline>
</headlines>
As you can appreciate, the structure that I provided to the above XML file is very simple to grasp. In short, all I did concerning this file was define a pair of <headline> tags for each of the headlines to be displayed, which wrap up a few child nodes composed of the <image>, <url> and <text> tags respectively.
For this example, I decided to code exactly ten <headline> entries, but as I explained before, this structure can be easily altered to fit different demands. After all, creating the appropriate XML file that feeds this AJAX-driven application wasn’t hard at all, was it?
Final thoughts
In this two-part series, I went through the development of a small yet highly expansible AJAX application that can be used for displaying a predefined number of headlines, in addition to their associated images and links.
As you saw here, the core modules can be easily tweaked with minor hassles. You might choose to do so if you are using a database table instead of an XML data file. Even the programming logic can be changed to request each headline separately. Indeed, the possibilities are numerous and exciting.
As usual, see you in the next web development article!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |