Writing Your RSS Code

Posted: Thursday, July 10, 2008

Writing Your RSS Code

Each RSS file contains information about your website and your description, all surrounded by matching start and end tags. The information and its tags are called an "item." Your RSS file will have to include at least one item. Generally, items are web pages that you'd like others to link to.

Note: The content which is placed in brackets should be replaced with open arrow and closed arrow

Item

Each item contains a TITLE, LINK, and DESCRIPTION. Start by placing the opening (item) tag at the top, then place the closing (/item) tag at the bottom, like this:

  • (item)

(/item)

Title

Add the (title) tag, following with the text of your title, then end with the ( /title ) tag. It would look like this:

  • (item)
    ( title ) The Title of Your First Story ( /title )
    (/item)
Link

Next, add your link information, beginning with ( link ), following with the actual hyperlink, then closing with ( /link ), to look like this:

  • ( item)
    (title)The Name of Your First Story ( /title)
    (link) http://yourdomain.com/yourpage.xml(/link)
    ( /item)
Description

For your description, you start with the opening (description) tag, then following with the actual description, then closing with the (/description) tag. Now you have this:

  • ( item)
    (title)The Name of Your First Story ( /title)
    (link) http://yourdomain.com/yourpage.xml(/link)
    (description) A brief description of your story (/description)
    ( /item)

If you have other stories you want to syndicate, you simply add more items. You can have up to 15 items, all stacked one above the other. Newer items are usually inserted at the top, with old items being removed from the bottom as they are replaced by new ones. Your code would look like this:

  • ( item)
    (title)The Name of Your Second Story ( /title)
    (link) http://yourdomain.com/yourpage.xml(/link)
    (description) A brief description of your story (/description)
    ( /item)

  • ( item)
    (title)The Name of Your First Story ( /title)
    (link) http://yourdomain.com/yourpage.xml(/link)
    (description) A brief description of your story (/description)
    ( /item)
Channel

Having defined items you want to distribute, you need to define your site as the "channel." You'll use the same tags as with the items: title, description and link. However, this time the information will be about your entire site, rather than a particular page. Your channel information would look like this:

(title)An Overall Title ( /title)
(link)http://yourdomain.com(/link)
(description) Interesting sentence or two about why people might want to read your stories and what you specialize in.(/description)

How does something reading our RSS file know that the information above is for your "channel" when it looks just like item information? Simple. As long as you don't surround this information with opening and closing tags, it won't be seen as item information but rather as channel information. Using just one item, you would have this:

· (title)An Overall Title ( /title)
(link)http://yourdomain.com(/link)
(description) Interesting sentence or two about why people might want to read your stories and what you specialize in.(/description)

  • (item)
    (title) The Name of Your Story<(/title>)
    (
    link)http://yourdomain.com/yourpage.xml(/link)
    A brief and inviting description of your story.
    (/item)
Define and Declare

There are a few last things you need to do.

First, you need to define the XML version you are using. You do this by adding the (?xml version="1.0"?) tag at the very top of the file, which says that this is written according to the XML 1.0 specifications.

Then, you have to declare what RSS version you are using. Everything you've done here is compatible with UserLand's popular RSS 0.91 version. However, it also matches UserLand's latest RSS 2.0 version. So you'll define the file as meeting that specification. You do this by adding: (rss version="2.0")

After the RSS tag, you need to add an opening (channel) tag. Altogether, this would be at the top of the file:

(?xml version="1.0"?)
( version="2.0")
(channel)

At the bottom of the file, after all the items you want to syndicate, you have to insert the closing channel (/channel) and RSS tag (/rss), in that order. The finished RSS format would look like this:

  • (?xml version="1.0"?)
    ( rss version="2.0")

    (channel)
    (title)An Overall Title (/title)
    (link)http://yourdomain.com(/link)
    (description) Interesting sentence or two about why people might want to read your stories and what you specialize in.(/description)
    (item)
    (title)The Name of Your Story(/title)
    (link)http://yourdomain.com/yourpage.xml(/link)
    (description)A brief and inviting description of your story.(/description)
    (/item)
    (/channel)
    (/rss)

Once you've created and validated your RSS text file, register it at the various aggregators, and watch the hits roll in. Any site can now grab and display your feed regularly, driving traffic your way. Whenever you update your RSS file, all the external sites that subscribe to your feed will be automatically updated. What could be easier?

BACK TO RSS BLOG



0 comments: