Tutorials | Getting started with Creating RSS Feeds
After reading the tutorial on Getting started with Syndicating RSS, perhaps you've decided to provide your own feed. This tutorial will help you get started creating an RSS file.
Why should I create a feed?
Providing an RSS feed is a great way for users to view the contents of your site quickly, without having to sift through older, previously viewed content, saving bandwidth. It also keeps the user coming back to your site; to view your content, all they have to do is stay subscribed, and they can view your content whenever they next check their aggregator. Additionally, other sites are able to show your headlines within their site (if you allow them); this promotes linking between a community of sites, gets more hits to your sites, and gives you better rankings on search engines. This means people can get a dynamic sneak preview of your site's content while browsing other sites, instead of just a regular link giving no details of what your site contains.
As explained in "Getting Started with Syndicating RSS", RSS is a subset of the XML markup language. Don't let the 'language' part scare you; it's nothing like a complex programming language such as C++ or Java. The key is in the 'markup' part - XML is a way of 'marking' or 'tagging' text to describe what it is (thus the use of 'tags'). The description of XML further down shows how text is tagged.
The advantage and strength of XML in fact lies in what it doesn't do, and not what it does. It describes the text within it, rather than dictating specifically how each element should be displayed; this leaves how it is displayed open to to interpretation by, of course, the XML Interpreter. This makes your XML document highly portable - you don't need to rely on a specific program to interpret the XML, ANY interpreter will do, whether it be on a Windows PC or on a mobile phone. It also means the document can be interpreted for different usages, eg. for users with accessibility requirements such as sight impairments. This is the reason why large documents that require portability, such as aircraft manuals, are marked-up in XML.
How do I create an RSS feed?
To create an RSS feed, you will need:
- Your own Website, or Web Server
- A text editor (such as the Windows Notepad)
RSS documents can be written with any text editor, but usually you will want to have them dynamically generated. If you have a dynamic web page that uses a database and/or text files to retrieve content, written in server-side languages such as PHP or ASP, you can generate the RSS file in a similar way to how you show content on your site. If you run a weblog and use a blogging tool, there's a good chance the tool generates an RSS feed for you. For that, you won't need to worry about how to write RSS documents, but this tutorial is available if you're interested anyway.
First, we need to explain some terms:
XML stands for eXstensible Markup Language, and is a broad description for text that is marked in a certain way by using tags. Text is marked by enclosing it within two tags. A tag is represented first by the 'less than' symbol (<), then by the name of the tag (e.g. 'bodytext'), then by the 'greater than' symbol (>). So, a tag that indicates the start of 'bodytext' content, known as the opening tag is thus:
The content must then followed up with a closing tag, which is the same as the opening tag, but start with a forward slash (/). So, for example, we could have this:
This is called an element.
A tag can also contain attributes that define it's content further, such as:
Look familiar? HTML, as in the language web pages are written in, has similar origins to XML. However, XML is different to HTML in that the tags XML uses can be anything defined by the author of the document. XML also has stricter rules than HTML, such as:
- tags are case-sensitive (<bodytext> is not the same as <BodyText>)
- all elements that have an opening tag must have a closing tag
- tags must be nested properly (if you mark an element as <bodytext>, then mark something inside it as <highlight>, you must close the </highlight> before you close the </bodytext>
While HTML is fairly loose on how you do things, and will generally work regardless, XML interpreters will generally display errors or fail completely if the document is not formed properly.
RSS stands for Really Simple Syndication, and defines a set of standard tags used to syndicate content from websites, so readers can access it easier.
To write a basic RSS document, you need to start off with:
The first line specifies the document as XML and the document encoding that will be used. The second line states you are using RSS and which version of RSS you are using.
Then, you add the start of the channel element, which contains information about the feed:
<description>John Smith's RSS Feed contains daily updates of John's opinions and news</description>
First, the channel element is opened. Then, we put a title element which is the title of your website or feed. The link element provides a link to your website. description is self explanatory. docs is a link to the RSS specification, you won't need to change that line. language defines what language the feed is in (see here for a list of language codes to use here). The image element allows you to add an image to your feed, such as a logo, and contains the URL of the image, it's title, where it links to when clicked, and width and height. Don't forget to add a closing tag to every element.
Now comes the real meat of an RSS feed - the item elements. Each item element represents a unique news item, headline, article or whatever you link to. Item elements are placed within the channel element, and you can have as many as you want, though generally only the newest 10 to 20 are included to save bandwidth - while RSS documents are quite small, you have to take into account the potential millions of subscribers, who will have their feed readers check the document possibly several times a day.
<title>John goes to the market</title>
<description><![CDATA[Today I went to our local flea market, and you'll never guess what I found...a brand new car for 50 bucks. Wow!]]></description>
<pubDate>Wed, 15 Jun 2005 12:00:00 +1000</pubDate>
All of the tags are fairly self-descriptive. We open up the item element, and inside goes the title of the item, a link to further information relating to this item. The guid is a unique ID for each item, that helps aggergators determine whether or not their user has viewed this item yet. It can be anything alpha-numeric you want, but it should be unique for every item from now until the end of time. Then comes the description, the content of the item.
You may find that <![CDATA[ and ]]> bit out of place. Those special tags indicate that the folling text should be taken literally, as written. Usually they are not required, but if you plan on using HTML tags to pep up your feed item's content, you should enclose all of it in the CDATA tag.
Lastly is the pubDate, the date when the item was published. This helps aggregators sort the items. It should always be written in the format shown: 3 letter day, number of month, 3 letter month, 4 number year, 24-hour time (HH:MM:SS), and your timezone (+1000 means 10 hours 00 minutes ahead of Greenwich Mean Time, the timezone of east coast Australia). There are many other tags you can use within your channel or item elements, visit http://blogs.law.harvard.edu/tech/rss for a complete list of every tag available in the RSS specification. Tags within an item can be written in any order you wish: you don't HAVE to have the title before the description, etc.
Now, to continue XML convention, we need to close off the remaining open tags.
Validating your RSS feed
Having completed your RSS feed you should validate it with an RSS Validator. This will ensure that you have created a truely well-formed document that conforms to the appropriate RSS standards.
Now, that may seem like a lot of work for something so simple, but like stated at the start of the tutorial - blogging tools may do this for you, or if you have written your own dynamic website, you'll only need to do this once. But in reading this you'll have learned something valuable, and hopefully it will help you understand better one more tool used on the internet today.
Please Note: if you have any questions about this tutorial please ask on our support forums
If you have written a tutorial of your own and would like to have it here on Cyber Tech Help all you have to do is Submit your tutorial and it will be reviewed by the Administrator.