Experience XML

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

 

  E x p e r i e n c e   X M L  | 2 
 

Contents Page
Chapter 1
XML – Empowering the Web
Introduction 3
Handicaps of HTML-JSP Pair 3
Case Study 1 4
Case Study 2 5
What is XML? 8
Why XML? 8

Chapter 2
Presenting XML Data
How does a browser understand XML? 10
Linking Style Sheets 11
Using XSLT 12
Using Java Script 14
Conclusion 18
A Few Exercises 19

Chapter 3
Applying XML – RSS
Introduction 20
XML Based Standards 20
RSS- Really Simple Syndication 20
Advantages of RSS 21
How RSS Works 22
Where else can RSS be applied? 22
How to create an RSS Feed? 22
A Sample RSS Document 22
Explanation 22
How to generate dynamic RSS? 24
Conclusion 23
A Few Exercises 23

Our Apologies to Tough Technocrats 24


Acknowledgements 25
Our Appeal to Readers 26
   
  E x p e r i e n c e   X M L  | 3 
 

Chapter I – XML – Empowering the Web

INTRODUCTION

Today, the community of web professionals can be broadly classified into two
categories namely, Web Application Developers and Web Engineers.

The web application developers make use of already existing technologies and develop
end-user applications (like an Online Shopping Mall). In contrast, the web engineers
develop the technologies, which are used by the application developers. Mostly, the
web engineers also would have been application developers in the beginning. But, they
develop a different attitude set in their minds.

The typical attitude which differentiates these two groups is the ability to identify
problems and invent solutions for them. For example, let us assume that an application
developer comes across a restriction of the technology, which makes him incapable of
implementing what he thought. He would modify his thoughts and hence the
application design to bend to these rules of restriction.

But, if the same person gets frustrated by the restrictions posed by the technology and
modifies the technology to remove that restriction, he ends up with the development of
an improved technology. Thus, in this process, he transforms himself to a Web
Engineer.

XML is a brain-child of such group of engineers, who were fed up with the restrictions
of HTML and other web standards.

Handicaps of HTML-JSP pair

Till now, we have been satisfied with the capability of browsers to understand HTML.
And, we, as web application developers, had ultimate monopoly over how our data
should be displayed in a browser. These things may make us feel comfortable. But,
these things are of no worth in today’s Information Sharing world. Let us see the
handicaps of HTML-JSP pair by analyzing some situations, which may arise in web
application development. These may be considered as short case studies, which will
help you to analyze and understand the problem.
  E x p e r i e n c e   X M L  | 4 
 

Case Study-1: You are not the ONLY person who uses the data in your
database

A private concern (say XYZ Technologies) decided to build a social-networking


site (similar to Orkut, Facebook) (say www.xyzportal.com). The application design
team of XYZ technologies decided to use DB2 for database and JSP for the server side
scripting, which manipulated the data from database and displayed the content in
HTML. They deployed their application in Websphere Application Server. All was
working well and they got huge revenue because of their user-friendly and attractive
design.

And, one day, another company (say SMS4Free.com) made a deal with XYZ
technologies to provide an additional functionality of online SMS to the registered users
of xyzportal.com. This way, it would attract more people to xyzportal.com. At the
same time, sms4free.com would get increased revenue because of the usage of their
facility by numerous registered users of xyzportal.com. This ended in a win-win
situation for both the parties.

IBM DB2  MySQL 
Express C  Database 
Database xyzportal.com SMS4Free.com

Web   
Sphere 
Apache 
(JSP)  (PHP) 

 
  E x p e r i e n c e   X M L  | 5 
 

Now, SMS4Free demanded the list of registered users from XYZ Technologies. But, XYZ
technologies did not like to give its entire database to SMS4Free because there was
some information of registered users, which should not be shared to any third-party, as
per the Terms of Service displayed during registration in xyzportal.com. It was at this
situation, the problem was presented to the application design team.

After enquiry, the application design team learned that the SMS4Free was using
PHP and MySQL as their back-end technologies. So, the only solution to share the data
was, to display relevant JSP page from xyzportal.com server itself, but with the logo of
SMS4Free.com. Thus, the application development team of xyzportal.com had to
develop these JSP pages, and ultimately the SMS application once again.

But, SMS4Free.com required maintaining a history of sent SMS in their database.


Since xyzportal.com was handling their SMS, just under their logo, they had to be given
access to the MySQL database of SMS4Free.com, which again had the same old
problems mentioned above.

Thus, our good old HTML and JSP architecture fails here, making lot of
complications. This needed a method of transferring data from one place to another,
which is independent of platform, application server or database.

Case Study-2: You need to process the data (from the database) at the client
side using JavaScript.

The same XYZ Technologies had an intercom telephone system in its campus.
All the intercom lines were managed by a separate Internal Telephone Department
located in its campus.

XYZ Technologies wanted to have a intranet web application to manage the


Internal Telephone Department so that the in-charge of the department need not be in
his office to do his task. He, as a resource, was planned to be used in any other job
and had to be provided with a computer terminal to take care of his actual job of
managing the intercom system.
  E x p e r i e n c e   X M L  | 6 
 

The web application design team was presented with the task of implementing a
web application which would enable the Intercom Manager to allocate phone numbers
to people, change already allocated phone numbers and so on.

One of the application developers (say Mr. ABC) was assigned with a task of
building a module under JSP to view the already existing phone number of any
employee and to change it when necessary. The design was as given in the figure
above.

Putting it in words, there had to be a web page which demanded the employee
id from the Intercom Manager. After entering the employee id and clicking on “Get
Details” button, his details must be retrieved from the database by AJAX requests and
displayed in appropriate text boxes provided in the same page. If the manager wants
to change the phone number, he can change the phone number and click on “Update”
button to submit the form.

Mr. ABC was quite thrilled when he saw the requirements. He had two separate
text fields in the form, which had to be filled with data from the database after AJAX
request. He could easily design a JSP page for the AJAX task of retrieving the phone
  E x p e r i e n c e   X M L  | 7 
 

number and employee name from the database and sending them back to the browser.
He could also finish his HTML design in less than five minutes.

His AJAX JSP page returned a response like

Mr. Thomas 456

The client-side (browser-side) now needed a Java Script which could process this
returned text after AJAX request and then assign the values in the appropriate text
boxes. Thus, the problem shrunk into splitting the single returned string into two
separate data. For this, ABC stored the returned text as a string in Java Script.

The Java Script specified above had the following logic:

1. Search for the “TAB” character (which separates the name and phone number)
2. Split the response into two strings, one from start to one position less than the
position of TAB character and another from one position next to TAB character
till the end of the string.
3. Assign these two strings as values to appropriate text boxes.

Mr. ABC succeeded in doing this job and was satisfied with his module.
Suddenly, he got a call saying that the Intercom Manager should be able to manage a
“Description” and “Designation Summary” fields, in addition to existing “Name” and
“Phone Number” fields. He was also notified that both the extra fields could contain
TAB character (!!!). It was because of this single constraint on the extra data, his
entire Java Script work had to be reconstructed. His existing logic could not be
extended to do this since the two extra fields can have TAB characters in them. Also,
he was aware of the possibility of another call in future asking him to add more fields
and collapse whatever logic in Java Script he thought now.

In this situation, the entire problem lies with the complexity and rigidity in
processing the strings in Client Side Java Script. If there had been an easy way to
process the data from the database at the client side, without any restrictions as
mentioned above, then, the application development and extension process would
become faster and reliable. The lack of this makes the conventional HTML based
approach very ineffective.

These two situations are the easily noticeable ones to illustrate the handicaps of
HTML-JSP pair. But, there are still more and they will be dealt in the forthcoming
sections.
  E x p e r i e n c e   X M L  | 8 
 

What is XML?

XML stands for eXtensible Markup Language. This is a markup language just like
HTML, which uses Tags. But, the purpose of using tags is different here. HTML used
tags to define how information must be displayed in the browser. But, XML tags are
used to organize and represent the information in an easy and platform independent
way.

With XML, we can invent our own tags and there are no pre-specified tags. You
can even have a XML document like the one below:

<shoppingmall>
<name> XYZ Shopping Mall </name>
<location> Chennai </location>
<productlist>
<product>
<id> 1001 </id>
<productname> XYZ Bulbs </productname>
<price> 100 </price>
</product>
<product>
<id> 1002 </id>
<productname> XYZ Water Coolers </productname>
<price> 15000 </price>
</product>
</productlist>
</shoppingmall>

We can safely assume that XML was designed as a new way to transfer
information via web.

Why XML?

XML is useful in a wide variety of situations. This has many advantages when
compared to the HTML.

1. Platform-Independent: XML is just a piece of text data, which is structured in an


organized way. It does not involve special file types or special software. So, any
software that can process text data can be used with XML. So, it becomes
platform independent mechanism for data representation.

2. Readability: XML documents can be read and understood by any ordinary user.
For example, when the browser or server crashes and returns the XML
information directly without processing, we can still be able to understand what
  E x p e r i e n c e   X M L  | 9 
 

it is trying to say. You would have easily understood that the example which we
gave previously was meant to say something about a shopping mall.

3. Easy Processing: Since XML presents the data in separate, organized clusters, it
becomes easy to process that data with anything that can process text data. For
example, the example XML document can be easily processed with Java Script to
extract the product names and prices alone. If the complete product list is given
as XML data to the browser, then, we can be able to build our own search
application, which can search the products from the browser (client-side),
without even contacting the server.

4. Strict Syntax: Though the tags of XML can be designed by the user, there is a
very strict syntax to represent XML data. The XML data is processed only after
the syntax check. Why should we have such a strict syntax? For example, if a
person has many optional features in coding, then, writing software to process
his data is very difficult. We have to deal with many conditions. But, if he has
no optional features, then the design of processing software becomes easier.
So, this is aimed at easing the design of processing code, either in JSP or Java
Script or what ever it can be.

5. Extensibility: XML data can be used to extend many applications. For example,
in the first case study we saw, XYZ technologies can just give only the required
XML data of users to SMS4Free.com. This XML data could be delivered as a XML
page to the SMS4Free.com on request anytime. And, SMS4Free.com can write its
own scripts to process that data. Even, they can construct a local database with
the XML file they received. Thus, XML serves as a way to extend applications.

6. Portability: Even a full database can be represented in XML format. So,


theoretically, it is possible to make a XML file, which can act as a database
backup. This backup in XML can be later processed by a easily developed
program to create a database and insert tables and records in ANY database
server, be it MySQL or DB2 or whatever.

These advantages make XML a powerful technology that can bring more faces to
the current World Wide Web.
  E x p e r i e n c e   X M L  | 10 
 

Chapter II – Presenting XML Data

How does a browser understand XML?

We have seen that the browsers understand only HTML. But, now we are saying
that we can present data to the users by means of XML. How is it possible?

If we store the shopping mall example (of previous chapter) in a file, say
shopping.xml in a server after adding

<?xml version=”1.0” ?>

in the first line, and serve it to Mozilla Firefox, it will look as follows

Surprised!!! How does our browser distinguish the XML tags with different
colours? The answer is that the browsers understand the XML data, i.e., they can
process the XML data but, they do not know how to display that data to the user.

So, it becomes the developer’s responsibility to tell to the browser how a XML
data has to be displayed. This can be done in many ways and each way has its own
advantage. Let us see them one by one.
  E x p e r i e n c e   X M L  | 11 
 

Method – 1: By linking style sheets

We can link some CSS style sheets to XML documents in the same way we link
them to HTML files. Let us now design a CSS file which contains the following text:

Filename: shoppingstyle.css
name{
background-color: #aaaaaa;
font-weight: bold;
text-align: center;
font-size: 16px;
}
location, id, price{
font-weight: normal;
text-align: left;
font-size: 12px;
}
productname{
font-weight: bold;
text-align: left;
font-size: 12px;
}
product{
display: block;
background-color: #eeeeee;
}

Now, let us open the previous file, say shopping.xml in any text editor and add
this line next to the line in which <?xml version = “1.0”?> is present.

<?xml-stylesheet type="text/css" href="shoppingstyle.css"?>

This line links our XML file with the CSS file and now, browser knows how to
display this content as it can understand the CSS file. Make sure that you save this CSS
file in the same folder as the xml file.

Now, type the address of that xml file in the browser. Now, you will not see the
previous display but the one shown below:
  E x p e r i e n c e   X M L  | 12 
 

In the CSS file, we have described how each tag in XML must be displayed in the
browser and the browser follows the instructions given in the CSS file.

Disadvantages of this method

The primary disadvantage of this method is that, we cannot add any extra data
apart from the XML data into the page, while displaying in the browser. All we can do is
just to specify how to display each XML element.

What if we want to display the data in the form of a table? What if I need to
have a form to capture user input in this page? This method cannot give solution to
such needs.

Where this method will be useful?

Whenever you have to display a list of users currently logged in, you can use
this. But, if you need any other options like LOGOUT to be displayed in the page, then,
put this in a separate frame and show.

Again, it sounds inefficient. So, if you really find situations where you need only
the data in the XML to be displayed, use this style.

Method – 2: By using XSLT

This is the most popular method of displaying XML data. This involves a
standard mix of HTML and XML specific syntax to display the XML data. This solves the
disadvantages of the previous method. In this method, you can display tables, forms or
any additional content to the XML data.

In this method, we will create a file called XSL (eXtensible Stylesheet Language)
file. This file is similar to a HTML file, which contains HTML tags. But, in between,
there are specific constructs used to extract the data from the XML file associated with
it. After extraction, these are displayed in the browser.

Now, look at the following XSL file and test it. After that, we will look into the
explanation of this code and reason out why the display is as it turns out to be.

Filename: shoppingxslt.xsl
<?xml version = "1.0" ?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">

<body>
<h1 align="center"> <xsl:value-of select="/shoppingmall/name"/> </h1>
  E x p e r i e n c e   X M L  | 13 
 

<h3 align="center"> <xsl:value-of select="/shoppingmall/location"/> </h3>

<table border="1">
<tr>
<td>Product ID </td>
<td> Product </td>
<td> Price (in Rs.) </td>
</tr>

<xsl:for-each select="/shoppingmall/productlist/product">
<tr>
<td> <xsl:value-of select="id"/> </td>
<td> <xsl:value-of select="productname"/> </td>
<td> <xsl:value-of select="price"/> </td>
</tr>
</xsl:for-each>

</table>

</body>
</html>

Now, in the shopping.xml file, in the second line ,i.e., in the line containing
<?xml-stylesheet….. content, replace the css with xsl and shoppingstyle.css with
shoppingxslt.xsl i.e., the second line must be like

<?xml-stylesheet type = "text/xsl" href="shoppingxslt.xsl" ?>

Confirm that you have stored the xsl file in the same folder as the xml file. Now,
type the address of the xml file in the browser. You will see something similar to the
above one.
  E x p e r i e n c e   X M L  | 14 
 

Explanation of the XSL code

Now, let us know what is meant by the XSL code given.

1. The <html xsl…> tag says that it is a XSLT document. You will be able to notice
two internet URLs in that tag. Don’t think that these will get the contents from
that URL. Actually, these places called namespaces must have a unique
identifier. And, the simplest way of getting unique identifiers is email address or
Internet URL because in these, no two resources in the same name exist. So,
they are used as identifiers only and not links to those URLs.
2. The <xsl:value-of> gives the value of a particular XML element. For example, if
we want to select the value of the <name> element in the shopping mall, we
give <xsl:value-of select = “/shoppingmall/name”>.
3. If there are multiple elements having same XML tag, we can use <xsl:for-each>
tag to loop through all these elements. Note that, in the code above, we have
used the <xsl:for-each> tag to loop through all the products. And, in each loop,
we have displayed the product id, name and its price using <xsl:value-of> tag.
4. We can notice that the XSL elements are embedded in the HTML structure.
Wherever we need to display XML data, we use XSL specific tags. Otherwise, we
use ordinary HTML tags.

Advantage

The most important advantage of XSLT approach is that we can have our own
HTML data, in addition to the XML data present in the XML file. This enables us to add
forms, tables and whatever we like.

Disadvantage

We specify the XSL style sheet’s filename in the XML file itself. So, for desired
display, we have to provide the XSL file as well as the XML file. If we want to change
the displayed content dynamically, at many times, we would have to change two files at
a time, XSL and XML file. This is highly inflexible.

Method-3 : By using Java Script

This is the most useful and flexible method of displaying XML data. This
provides lots of freedom to users for displaying XML content. In fact, it is by this
method, the power of XML can be greatly utilized.

There is a separate functional block called ”XML Parser” in almost all browsers.
Technically, a parser is a program that reads a raw data (preferably in text file format
  E x p e r i e n c e   X M L  | 15 
 

but not necessarily) and converts it into some usable data. For example, a parser can
be written in any programming language to extract all the dates from a given text file.

XML parser in the browser reads the XML document and converts into a tree like
object, which can be accessed by Java Script. The browser, which thinks of anything in
a web page as a separate object, is technically called a DOM (Document Object Model)
based browser.

Similar to AJAX, here also, there is a difference in accessing the XML parser in
different browsers. Microsoft based browsers follow a separate syntax for calling this
XML parsers where other browsers follow a completely different one. Again, similar to
AJAX, the site W3schools.org came to the rescue and provided a Java Script code that
will work in all browsers.

Browser Independent Java Script Code to start the XML parser


try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert("Your browser does not support XML parsing.");
}
}

After the above code is executed, xmlDoc is a variable that can be used to
access any XML document. Now, let us see how to access an XML document with the
xmlDoc variable.

There are some properties and functions of this xmlDoc variable. These
properties and functions help us to use it. They are listed below.

1. Async property:
This property, when set as “false” will prevent the execution of the Java
Script code till the full XML document is loaded into the XML parser. For
doing this , we will type:

xmlDoc.async=false;
  E x p e r i e n c e   X M L  | 16 
 

2. Load function:
This function helps us to specify the name of the xml document to be
loaded. For example, to load a file called “xyz.xml” into the browser’s
XML parser, we will type:

xmlDoc.load("xyz.xml");

Travelling through nodes in XML tree using Java Script

We can access the values of each and every element of the XML document using
Java Script.
Filename: shopping.xml
<?xml version = "1.0" ?>
<shoppingmall>
<name> XYZ Shopping Mall </name>
<location> Chennai </location>
<productlist>
<product>
<id> 1001 </id>
<productname> XYZ Bulbs </productname>
<price> 100 </price>
</product>
<product>
<id> 1002 </id>
<productname> XYZ Water Coolers </productname>
<price> 15000 </price>
</product>
</productlist>
</shoppingmall>

To load this file in the browser’s XML parser, we need to type the browser
independent XML parser loading code given above and then give

xmlDoc.async=false;
xmlDoc.load("shopping.xml");

To access the value of the first <id> element in the XML document, we have to type
xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue

Similarly, to access the value of the second <id> element of the XML document, we
have to use
  E x p e r i e n c e   X M L  | 17 
 
xmlDoc.getElementsByTagName("id")[1].childNodes[0].nodeValue

How to display the entire product list?

Using the ‘for’ loop, we can navigate through all the products in an XML
document. Let us see how to display the entire product list.
<html>
<head>
<script type="text/javascript">
function display()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert("Your browser does not support XML");
return;
}
}
xmlDoc.async=false;
xmlDoc.load("shopping.xml");
var root=xmlDoc.getElementsByTagName("shoppingmall")[0].childNodes[1].
childNodes[0].nodeValue;
document.write("<h1>"+root+"</h1>");
var i;
for (i=0;i<2;i++)
{
document.write("<hr> <br>Product ID:");
document.write(xmlDoc.getElementsByTagName("id")[i].childNodes[0].
nodeValue);
document.write("<br>Product Name:");
document.write(xmlDoc.getElementsByTagName("productname")[i].childNodes[0].
nodeValue);
document.write("<br>Product Price (in Rs.):");
document.write(xmlDoc.getElementsByTagName("price")[i].childNodes[0].
nodeValue);
}
}
</script>
</head>

<body onload="display()">
</body>
  E x p e r i e n c e   X M L  | 18 
 
</html>

The above code will give the following display:

Advantages of this method

The main advantage of this method is that, we can load the entire XML
document and we can choose what elements should be displayed to the user. This
feature is not available in the previous two methods.

The next advantage is that you are not adding any code to the XML file. In other
two methods, we are adding the linked CSS of XSL style sheet to the XML file. So, this
allows the same XML file to be used under different circumstances by different people.

We have the liberty of doing whatever we want with the available data. In the
other two cases, we can only display them. But, here you can even manipulate them
using Java Script commands.

So, ultimately, this becomes the most preferred method for using XML. But,
XSLT is widely used because of its simplicity and flexibility.

Conclusion

The three methods of using XML can help you in different aspects of your web
application development. By now, we expect you to be clear regarding why we use
XML and how we use XML. This will help you to build very powerful and interoperable
web applications.
  E x p e r i e n c e   X M L  | 19 
 

A Few Exercises

1. Try to guess whether a particular site uses XML or not by checking the range of
services that site offers. Analyse a minimum of 5 web sites and justify your
answer.
2. Develop a XML document that can be used to hold the attendance of a class.
The name of the student, register number of the student and the number of
days for which he is present must be stored. The details of all the students of
the class must be stored. In addition, the name of the class teacher also has to
be stored.
3. Try to build a CSS style sheet to display the XML file which you built for exercise
2.
4. Build and check a XSL style sheet to work with the XML file for exercise 3.
5. Build a Java Script based HTML page that will display the first ‘n’ student details
where the value of ‘n’ is entered by the user in a text box.
  E x p e r i e n c e   X M L  | 20 
 

Chapter III – Applying XML - RSS

Introduction

Till now, we have seen how to create XML documents and how to display them
in a browser. Today, we are using many XML based applications without knowing that
they use XML. There are many web standards which have been developed later based
on XML. This chapter deals about these standards which are based on XML.

XML Based Standards

XML is used in most web standards. Some of them are:

1. RSS (Really Simple Syndication)


2. SVG (Scalable Vector Graphics)
3. X-Forms
4. WAP (Wireless Application Protocol) and many more.

RSS – Really Simple Syndication

You might have very well seen the symbol given above. Have you ever
wondered what it is for? It is a notation for an RSS feed. The best example of an RSS
feed is the news updates in the form of FireFox bookmarks. For example, the news
paper “The Hindu” offers RSS Feeds. With this, you can view the current news headings
instantly, without going to the Hindu’s web site.

How to add “The Hindu” RSS Feed to Firefox Bookmarks?

1. Go to the web site www.thehindu.com


2. Click on the RSS Feeds link.
3. Click on the    News Update  if you want to subscribe for instant News Update.
4. Click on the “Subscribe Now” button.
5. Choose the Bookmarks Toolbar for “Create In” option.
6. Click on “Add”.
7. Now look at your Bookmarks toolbar for a new entry.
8. In order to view latest news, you can just click on this bookmark and click on the
entry to view the full text news.
  E x p e r i e n c e   X M L  | 21 
 

Advantages of RSS
1. The head lines can be seen right from the Browser’s toolbar.
2. The RSS feeds deliver headlines in XML format. This makes it light-
weight.
3. The RSS Feeds can be reloaded as and when necessary to get the
updated news.
4. This involves very minimum data traffic. So, RSS Feeds load very
quickly.
  E x p e r i e n c e   X M L  | 22 
 

How RSS Works?

Whenever we choose to reload a RSS bookmark from Firefox, it sends a request


to the Hindu Site and the Hindu Site sends an XML file back to the browser. This XML
file has a standard format (that is, RSS Format) understood by the browser and
displayed as a menu.

Where else can RSS be applied?

Though RSS is applied mostly in news industry, it can also be applied in other
areas like:

1. Product updates in a shopping mall


2. Mail Inbox update (GMail provides this facility)
3. Admission Updates for the administrator of University Admission System
And so on…

How to create an RSS Feed?

As we said, RSS feed is nothing but an XML file. So, you can create an RSS Feed
with notepad also. But, to update that RSS feed with your site’s new information, you
will have to use some JSP program that reads and modifies that XML file.

A Sample RSS Document

FILENAME: rss.xml
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Feed Title</title>
<link>http://localhost:8080/illuminati/</link>
<description>XYZ Product List</description>
<language>en-us</language>

<item>
<title>XYZ Keyboard-Rs.1500</title>
<link>http://localhost:8080/illuminati/showproduct.jsp?id=13</link>
<description>Rs.1500</description>
</item>
<item>
<title>xyz computer-Rs.19000</title>
<link>http://localhost:8080/illuminati/showproduct.jsp?id=10</link>
<description>Rs.19000</description>
</item>

<item>
<title>XYZ Table-Rs.1500</title>
<link>http://localhost:8080/illuminati/showproduct.jsp?id=8</link>
<description>Rs.1500</description>
</item>
</channel>
</rss>
  E x p e r i e n c e   X M L  | 23 
 

Explanation

The RSS feed starts with the usual XML starting line. The second line includes
the key word <rss> Then, feed title will appear in the title bar of the XML page, if
viewed in a browser. Link is the URL of the homepage of the site from which this RSS is
served. Description is a short text for user defined description of RSS content.
Language specifies the language used in the RSS feed. In this case, it is English (US).

After all these tags, each menu or news item is enclosed in <item> tag. The
title is the text displayed in the menu of Firefox. Link is the URL of the web page to be
loaded when the menu item is clicked. Description is shown for each item, when viewed
separately as a XML page in browser.

How to generate dynamic RSS Feeds?

To generate dynamic RSS Feeds, we can use JSP to query the database and
write the results to a file in XML format. This XML file will be served as an RSS Feed.

An Important Note: RSS can be recognized only when served from any server.
When you store RSS xml file in some local folder and open it in browser, it will not
display it as a feed. So, store your RSS xml files in the WebContent Folder of your
server.

Conclusion

This is not the end of XML. There are many technologies based on XML and
there are many technologies yet to be invented. Who knows? May be you could invent
the next XML based technology or even a challenger to XML. The ultimate concept
which we want you to know is, the problems are the things which create new and
sophisticated tools and standards. So, expect problems, look out for problems and try
to give your own solution to them. That is, in simple words, live as an engineer.

A Few Exercises

1. Try to identify where you can implement RSS in your solution for TGMC.
2. Build an interface to add a product to a shopping mall. This addition process
must add the product to the database, and, at the same time, update the RSS
Feed.
3. Try to know about SVG (Scalable Vector Graphics). These are graphics
generated based on XML. With this, you can store complex graphics in very
small storage space.
4. Gather details regarding X Forms in W3schools web site and try to understand
what they are.
  E x p e r i e n c e   X M L  | 24 
 

Our Apologies to Tough Technocrats

Most of the technical people might not very well appreciate this tutorial as it
often describes some things in a non-standard or non-ideal way. But, as it is meant
for beginners and non computer stream students, we can’t expect them to
understand the concepts like:

“there is an object called DataSource in a package called sql which is in


turn a sub package of a package called java” or “the first row in a result
set would contain metadata required for the processing of the returned
result set”.

In another view point, we could see people running away from these ventures,
when presented with such kind of hi-fi data. But, at a later point of time, if we feed
these technical data as an add-on to what is already known, they are able to grasp
it. It is noted that this is in contradiction to the pedagogical approach.

We believe that it is enough to understand what each software does, in order to


successfully complete a TGMC venture. So, please bear with our non-standard
explanations and examples. These are aimed at better understanding of some
working concepts by beginners and not aimed at misguiding the students.
  E x p e r i e n c e   X M L  | 25 
 

Acknowledgements

We would like to acknowledge the following people/organizations for their direct


or indirect help to us in preparing this tutorial series.

Mr. R. Amirtharajan, Senior Lecturer, Department of ECE, SASTRA

Our primary thanks goes to him. It is he who motivated us to do something for


others apart from learning something for ourselves. He provided his desktop system for
us to build our TGMC solution and for preparing this tutorial series. His feedbacks on
our solution and this tutorial have always been useful. Without his Computer, we don’t
believe that we could have done this tutorial as well as our solution for TGMC. We feel
that it is our duty to thank him.

Mr. Rajaraman Srinivasan, Former Senior Lecturer, Department of IT,


SASTRA

He was the one who taught us the basic concept of web applications, client-
server architecture, databases, etc. This tutorial, in fact, includes most of the ideas
conveyed by him to us. His seminar for a single day on all these IBM tools for all
students of SASTRA made us to do the TGMC for the last year. This year, as we don’t
have him in teaching profession, we realize that it is our duty to carry on his job. This
tutorial is a brain-child of that realization. Our special thanks to him.

IBM Academic Initiative

Obviously, we have to thank the IBM Academic Initiative team for providing us a
platform to know about these fascinating technologies. Without this, our regular course
work would have not kept us well informed about the web. This has been our
basement for our interest and knowledge-acquisition in hacking, web security, web
designing, etc. Thanks to IBM for making us the fans of web technology and fans of
Linux. We would like to extend our support, if possible, even in the smallest means for
this Academic Initiative and we hope that this tutorial is an example of our commitment
to Academic Initiative of IBM.

And at last, our student friends, for their constant feedbacks,


suggestions and doubts from which we learnt much more than what
we already knew. Thanks and our best wishes to our friends for their
future.
  E x p e r i e n c e   X M L  | 26 
 
Our Appeal to Readers

This is just an introductory material for the XML. There are more wonders in XML than
anyone might imagine.

Anyways, we, the illuminati team, will not be able to participate in TGMC next year since
we would be out of our colleges by then. But, still we will be pleased to help you out in any
issues that may arise during the course of your solution development. Don’t bother to drop an
email to gearuptotgmc@gmail.com. We will keep this email id active for incoming support
requests.

We request you to pass on this tutorial to all your friends. Tell them about the
experience you had in reading this tutorial. And, don’t ever have the habit of concealing this
tutorial just with you, just because sharing this with others makes them also knowledgeable in
these technologies. Because, competition has a meaning only when equally powerful opponents
compete. So, we advise you to empower your opponent before you start fighting, so
that you will fight the bravest fight and not the cowardly ones.

Again, Thanks for your supports and feedbacks.

Any comments/feedbacks can please be sent to gearuptotgmc@gmail.com for correction


in the future. We will be pleased to correct the mentioned errors. You can also mail us for
clarifications. We will provide you with explanations, if we can and if we know.

All the Best!!!!!

-The Illuminati

(G. Vivek, S. Kamal Raj, Srinivas Mitpellywar),

SASTRA University.

TER –X : VALIDATING USER

You might also like