Monday 8 July 2013

The Care Homes Directory News Syndication

Spreading the News

Due to the nature of our development cycle we have been able to rapidly develop a new feature providing our news articles as RSS and Atom syndication feeds. We thought writing an article to expand on the release would be a good thing.

Both our care and nursing  related news feeds are available to both users and web sites allowing access to our news stories by linking inward to our web site. If you run a website you are free to use our feed directly from your website.


RSS and Atom are two popular methods for syndicating content so it was a simple progression to provide a feed to our visitors. The feeds provide the latest 13 headlines along with description , link back and other data.



A screen shot of the HTML head markup showing the RSS and Atom feeds.
RSS and Atom Feeds



RSS Feed

Creating an RSS feed is simple and we just had to add an output filter to change it from HTML markup to XML markup.

The format of RSS is very simple and we went with RSS 2.0 to take advantage of this simplicity. One thing we noticed is RSS has no official body to guide the standard and there are a few differing versions.

Apart from this little problem it seems to be a widely used format so we feel that not offering it would be a worse situation for us.

Each feed is encapsulated inside some <rss> tags which we have set the version attribute to 2.0 as we decided to use this version.
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
  ....
</rss>

Next you need to add the markup for the actual feed so you give it a title a link to the main page and a short description of the feed.
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
  <title>My Feed Title</title>
  <link>http://www.example.com/rss.php</link>
  <description>This is an example description for an RSS feed.</description>
  ....
</rss>

After this each we can add the actual content of the feed for us this is our news headlines which are the 13 most recent stories. It was simple for us to just use existing code to fetch the data so it was a simple task.
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
  <title>My Feed Title</title>
  <link>
http://www.example.com/rss.php</link>
  <description>This is an example description for an RSS feed.</description>
  <item>
    <title>Feed Item One</title>
    <link>http://www.carehomes.net/feed_item.php</link>
    <description>Feed item one description.</description>
  </item>
  <item>
    <title>Feed Item Two</title>
    <link>
http://www.carehomes.net/another_item.php</link>
    <description>Feed item two description.</description>
  </item>
</rss>

The last thing to do is output the correct header for the content we tried to use application/rss+xml but we found this did not work so well with browser so we switched to just application/xml.
header('Content-Type: application/xml');

And below is the result of our new care and nursing related RSS news feed allowing visitors and site owners to access our news. We like to use Akregator for accessing our news feeds and have used it in the past with other websites feeds.

Over time we will be reviewing our RSS feed and adding some additional tags if we feel they add some value to the product.
Screen shot of the RSS news feed page.
RSS News Feed


Atom Feed

Now we have finished implementing the RSS feed we decided to support the other popular syndication format called Atom. This format seems to have a standard body to help guide the development of the standard which can be seen as a good thing.

Atom is defined in RFC4287 and this is the specification we use while developing although there might be other versions of the specification this is good enough for us.

Like RSS an Atom feed is an XML packet containing information on the feed as well as the content from the feed.

The feed is encapsulated inside a set of <feed> tags for the root node then some information about the feed its self.
<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
  ....
</feed>

After the feed data has been defined each element of the actual feed is inside the <entry> tags this contains the data for that item. For us we define the <title>, <link>, <id>, <updated> and <summary> tags so the actual entry looks like this.
<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>My Atom Feed</title>
  <link href="http://www.example.com/atom.php" />
  <updated>2013-07-08 13:55:48</updated>
  <author>Feed Author</author>
  <id>http://www.example.com/</id>
  <entry>
    <title>Entry One</title>
    <link href="http://www.example.com/entry1.php" />
    <updated>2013-07-09 13:55:48</updated>
    <author>Feed Author</author>
    <id>http://www.example.com/</id>
  </entry>
  <entry>
    <title>Entry Two</title>
    <link href="http://www.example.com/entry2.php" />
    <updated>2013-07-10 13:55:48</updated>
    <author>Feed Author</author>
    <id>http://www.example.com/</id>
  </entry>
</feed>

From this markup you can see it is a simple task to implement a syndication feed and our development time for it was very short because most of the leg work had been done before hand. We use our domain name for the id as this is unique to us and we will have the domain for a long time.


Picture of an atom feed inside a Firefox browser.
Atom News Feed


Conclusion

Development of the news syndication feed was rapid and the feeds were release the next day due to this. We hope the service helps others to keep up to date but also anyone with a website can use our feed for free and we encourage this.

Same as always we will be reviewing our news system and feeds at some point in the future to try and improve them. We will also be making some more changes to our news system very soon.

We will be publishing an article covering profiling and debugging PHP scripts to help fix problems and improve you code base.

No comments:

Post a Comment