We already have learned about RSS, use of RSS in part-I as well as some Vocabulary of RSS and information of tags in part-II.
In this part-III, we will learn practical purpose of RSS. So be ready for that...
Building its personal RSS feed, step by step
At start, this is just a simple text file, created with any text
editor. But an XML editor is more convenient. The name may be, for example: "feed.xml".
The overall structure is as that:
1
2
3
4
|
<? xml version = "1.0" ?> < rss version = "2.0" > < channel > </ channel > |
1) Define the source, by the channel tag
The channel will be the same for all your RSS feeds. These tags
are required:
- title: the title of your website, may be the one in the
title tag of the home page.
- link: the URL of your website: example: http://www.shivajisoft.com
- description: description of your website, about 200 characters,
this may be the text assigned to the content attribute of the
description tag, in the head section of the home page.
1
2
3
4
5
|
< channel > < title >Shivaji Maharaj</ title > < description >History of Shivaji Maharaj...</ description > </ channel > |
2) Add an image
This is optional. Design a small image (88x31 for example) in a common format
(gif, jpg, png) and put in into the same directory that the RSS file.
The "image" tag is a sub-element of the channel tag
- url is the address of the image itself.
- link is the address of the page displayed when one clicks on the
image.
1
2
3
4
5
6
7
8
|
< channel > < title > </ title > < link > </ link > < image > </ image > </ channel > |
3) Add a new
Now, we will add a web page to display an information. This is
an "item" tag, a sub-element of channel, and this components
are required:
- title: the title of the article.
- link: the URL of the page.
- description: a summary of the article, about 200 characters.
1
2
3
4
5
|
< item > < title >History of Legends</ title > < description >History of Shivaji Maharaj, Mahatma Gandhi etc.</ description > </ item > |
4) Add more items
More items may be added to this channel.5) Upload the file
Put the feed.xml file into your website, among other web pages.
6) Validate the file
You may use this online RSS feed validator.
7) Make it available
This is accomplished by adding an RSS button on the home page. A click on the button should display the XML file you have created.
1
2
3
|
If the image is not displayed, use a complete URL, as http://www.shivajisoft.com/rss.gif, for example.
8) Updating the feed
To publish further articles, you have just to add items, and remove older ones to keep the number of articles constant.
Example: the complete file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<? xml version = "1.0" ?> < rss version = "2.0" > < channel > < title >Shivaji Maharaj</ title > < description >History of Shivaji Maharaj...</ description > < image > </ image > < item > < title >History of Legends</ title > < description >History of Shivaji Maharaj, Mahatma Gandhi etc.</ description > </ item > < item > < title >Forts</ title > < description >Information about Forts</ description > </ item > </ channel > </ rss > |
How browsers know there is an RSS feed on a website
You have created an RSS feed and it is now stored at root of your website.
You must let browsers knowing the existence of this file and its location,
when they enter and display the home page (or any other page if you want).
Firefox will display the feed icon into the URL field, Internet Explorer on
the bar of commands.
To activate them, insert the following line into the source code of the page,
anywhere inside the <head> </head> section:
1
2
|
< link rel = "alternate" type = "application/rss+xml" |
Replace the URL by your domain name with the path and filename of your RSS
feed.
And if the file is in the atom format, replace rss+xml by atom+xml.
Tools to generate and display RSS feeds
- Feed Validator. Enter the URL of your file to check the feed.
- Bioloide. Online RSS generator and editor, written in PHP.
- RSS Reader. PHP function to display an RSS feed on a Web page, from a local or remote file.
Conclusion :
I hope that this article would have helped you to learn about RSS, its usage and simple way to publish that for websites. Your feedback and constructive contributions are always welcome.
No comments:
Post a Comment