RSS 0.91 and 0.92 feeds are created in the same way; the additional elements found in 0.92 are well-handled by the existing RSS tools.
Of course, you can always hand-code your RSS feed. Doing so certainly gets you on top of the standard, but it's neither convenient, quick, nor recommended. Ordinarily, feeds are created by a small program in one of the scripting languages: Perl, PHP, Python, etc. Many CMSs already create RSS feeds automatically, but you may want to create a feed in another context. Hey, you might even write your own CMS!
There are various ways to create a feed, all of which are used in real life:
XML transformation
Running a transformation on an XML master document converts the relevant parts into RSS. This technique is used in Apache Axkit-based systems, for example.
Templates
You can substitute values within a RSS feed template. This technique is used within most weblogging platforms, for example.
An RSS-specific module or class within a scripting language
This method is used within hundreds of little ad hoc scripts across the Net, for example.
We'll look at all three methods, but let's start with the third, using an RSS-specific module. In this case, it's Perl's XML::RSS.
Creating RSS with Perl Using XML::RSS
The XML::RSS module is one of the key tools in the Perl RSS world. It is built on top of XML::Parser--the basis for many Perl XML modules--and is object-oriented. Actually, XML::RSS also supports the creation of the older versions of RSS, plus RSS 1.0, and it can parse existing feeds, but in this section we will deal only with its 2.0 creation capabilities.
Incidentally, XML::RSS is an open source project. You can lend a hand, and grab the latest version, at http://sourceforge.net/projects/perl-rss.
Examples 4-8 and 4-9 show a simple Perl script and the feed it creates.
Example 4-8. A sample XML::RSS script
#!/usr/bin/perl
use Warnings; use Strict; use XML::RSS;
my $rss = new XML::RSS( version => '2.0' );
$rss->channel( title => 'The Title of the Feed', link => 'http://www.oreilly.com/example/', language => 'en', description => 'An example feed created by XML::RSS', lastBuildDate => 'Tue, 14 Sep 2004 14:30:58 GMT', docs => 'http://blogs.law.harvard.edu/tech/rss', );
$rss->image( title => 'Oreilly', url => 'http://meerkat.oreillynet.com/icons/meerkat-powered.jpg', link => 'http://www.oreilly.com/example/', width => 88, height => 31, description => 'A nice logo for the feed' );
<channel> <title>The Title of the Feed</title> <link>http://www.oreilly.com/example/</link> <description>An example feed created by XML::RSS</description> <language>en</language> <lastBuildDate>Tue, 14 Sep 2004 14:30:58 GMT</lastBuildDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs>
<image> <title>Oreilly</title> <url>http://meerkat.oreillynet.com/icons/meerkat-powered.jpg</url> <link>http://www.oreilly.com/example/</link> <width>88</width> <height>31</height> <description>A nice logo for the feed</description> </image>
After the required Perl module declaration, you create a new instance of XML::RSS, like so:
my $rss = new XML::RSS (version => '2.0');
The new method function returns a reference to the new XML::RSS object. The function can take three arguments, two of which are of interest here:
new XML::RSS (version=>$version, encoding=>$encoding);
The version attribute refers to the version of RSS you want to make (either '2.0' or '1.0', or, if you fancy being a bit retro, '0.91'), and the encoding attribute sets the encoding of the XML declaration. The default encoding, as with XML, is UTF-8.
The rest of the script is quite self-explanatory. The methods channel, image, textinput, and add_item all add new elements and associated values to the feed you are creating, and the print $rss->as_string; prints out the result. You can also call the $rss->save method to save the created feed as a file.