Tuesday, May 13, 2008

How to include RSS feeds into your components using OPML

It is really easy to include RSS feeds and links in your components - all you have to do is to place a buckminster.opml file in the root of your component (or tweak the properties if you want to call it something else, and place it elsewhere).

The OPML file itself has a very simple XML syntax. You start of with the usual xml declaration and declaring that you are using OPML 2.0.

<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">

This is followed by a head declaration where some information about the content of the OPML file is kept.

<head>
<title>Component information for org.demo.exampleComponent</title>
<dateCreated>Mon, 14 Apr 2008 14:18:51 GMT</dateCreated>
<ownerName>Your name, or name of project</ownerName>
<ownerEmail>contact.us@somewhere.com</ownerEmail>
</head>

And after the head comes the body part that consists of a sequence of outline elements - they can be nested if you want to use "subfolders".

<body>
<!-- outline elements --!>
</body>

A regular link (non feed) is expressed in an outline element like this:

<outline text="Cloudsmith" description="Cloudsmith's site" url="http://www.cloudsmith.com" language="unknown" title="Cloudsmith" type="link" />

And a feed is just as simple:

<outline text="My Feed" description="This is my feed" htmlUrl="http://www.somewhere.org" language="unknown" title="My Example Feed" type="rss" version="RSS2" xmlUrl="http://feeds.somewhere.org/examplefeed"/>

In both of the above examples - the "text" attribute is the label typically used in the RSS reader's bookmarks. Some OPML viewers use the title instead, and the reader may or may not show the description. Regular links (type="link") should use the "url" attribute for the link, and a feed ("type="rss") should use the "xmlUrl" attribute for the feed, but also add a link to a human readable web page - this is done by using the "htmlUrl" attribute, and it is often a link to the page where it is possible to subscribe to the feed, or read its content online.

In the feed example above, the feed type is "rss" - and the version "RSS2". A feed should always have the type set to "rss" (including atom feeds, but for atom feeds, the OPML spec is vague - I use "atom" as the version and it works just fine). These tags are mainly for a processor of the OPML itself, a feed reader will look at the actual feed to determine its type anyway. You can read more about the OPML 2.0 standard here.

And then finally, a subfolder is very simple to create:

<outline text="A Subfolder">
<outline .... />
<outline .... />
</outline>

Even if the creation of a component's OPML (at least for now) is done via manual editing of XML, I hope the examples above show that it is really quite easy.

No comments: