PreviousNext…

Site revealed: RSS feeds

Background

For a long time I didn’t "get" RSS, and what it could offer to the humble Domino-based weblog. Then I had an epiphany, and discovered NetNewsWire Lite for my Mac. So far, the best news aggregator I’ve tried which works for the Wintel crowd is AmphetaDesk (it’s browser-based, so is actually multi-platform).

Anyway, an excellent place to start with getting an RSS feed into your Domino application is over at Notestips. Mike has had feeds for articles, comments, news, and so on for some time. He wrote a good article about RSS back in April last year, entitled Creating an RSS news feed in Domino R5.

What I did here

I used Mike’s article as a starting point, and found it very useful. It cuts through the guff and tells you what you need to know, with one caveat: you don’t need to close the <channel> tag off before embedding your view with its <item> tags — these can quite happily sit within the channel. In fact, the whole feed can be a lot simpler in terms of header tags and so forth if you opt for the 0.92 route (my chosen flavour edit back when I originally wrote this - not now. Now I use RSS 2.0). See the example files and additional specification over at the RSS validator site for more info (with thanks also to Julian!)

Anyway, eventually I decided I wanted to expand upon the simple link style of feed, and provide the entire content of my blog entries as an RSS feed. So here I shall explain how I did it, but first, let’s go over the pitfalls of such an approach!

Initial issues

Being the naive young whippersnapper that I am (OK, OK, I’m 30 34), I just created the requisite tagged up view, and included the entire blog entry field. Oh dear oh dear. RSS is a dialect of XML, and XML is a tagging language. The last thing it wants is extra tags cluttering up the place. Consider this RSS fragment, with raw HTML dumped into it (i.e. what I was doing in my original view):

<?xml version="1.0" encoding="UTF-8"?>
<documents>
  <doc>

    <subj>
      A subject line
    </subj>

    <content>
      <p>So anyway, there I was walking down the street, when 
      <strong>My God!</strong> I saw him! I was like…</p>
    </content>

  </doc>
</documents>

Copy and paste the above into a new XML file and serve it up in your browser of choice. No good! Either the XML won’t come out at all, or the browser will simply break the HTML tags down into additional tags within the XML. No good for an RSS feed, and in fact this simply won’t validate (the XML file, "nogood.xml", is attached if you’re lazy).

So, we need to ensure that the nested HTML comes through, but doesn’t compromise the XML’s integrity. The answer is pretty simple: use CDATA. This allows you to create "islands" of code (doesn’t just have to be HTML) within your XML that won’t freak it out. Taking the above XML extract as an example, we’ll try again ("justfine.xml"):

<?xml version="1.0" encoding="UTF-8"?>
<documents>
  <doc>

    <subj>
      Valley girl subject
    </subj>
	
    <content>
      <![CDATA[[<p>So anyway, there I was walking down the street, when 
      <strong>My God!</strong> I saw him! I was like…</p>]]]>
    </content>

  </doc>
</documents>

Further issues: absolute versus relative

OK, so the XML is now well-formed. It’s still not right for a feed though. My blog entries regularly link to other pages within my site. These links are pretty short, because I use a base ref tag in my site’s <head> section. But that’s no good to the user reading my blog entries in an aggregator! So, Domino comes to the rescue here also. A simple @ReplaceSubstring call, which takes my standard-format internal links and converts them to fully distinguished URLs. Taking a simple example, here’s how:

baseURL := "http://" + @ServerName + "/" + @LeftBack(@ReplicaID; ":") +
@RightBack(@ReplicaID; ":") + "/";
@ReplaceSubstring(FIELD_NAME_HERE; "a href=\"0/";
"a href=\"" + baseURL+ "0/");

Don’t forget to do images and view links etc. too!

Finally, why not reference your feed in your site’s navigation bar? Assuming you’re using a browser that supports site navigation bars, you can have your RSS feeds come up as "Other Versions" in the "More" menu. Here’s the code you need (in the site’s <head> section):

<link rel="alternate" type="application/rss+xml" title="Blog RSS feed" href="whatever the URL is for your feed">

In summary

So there we have it. It isn’t very hi-tech, in that no cool Java XML processing is used, or anything like that (Java is very good at parsing and processing XML), but the end result, usually, is valid RSS. As with HTML and wot-not, it can’t hurt to pass your feeds by a validator every now and again. The main validator I use was created by Mark Pilgrim and Sam Ruby, and it’s very good. I use it regularly to pick up on errors in my blog feed (they’re easily broken when you have full content in them), and you should too!

If you want to know more about the drive for valid RSS, the arguments for and against future parsers becoming less strict, and so on, then you should check out Mark Pilgrim’s articles for O’Reilly’s XML.com — a couple of them are linked in the "Further reading" section.

Further reading

Downloads

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";
File Attachment Icon
nogood.xml
File Attachment Icon
justfine.xml