SunQuest
 
       XML Tutorials
  Home arrow XML Tutorials arrow Page 4 - RSS 2.0
Try It Free
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML TUTORIALS

RSS 2.0
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-03

    Table of Contents:
  • RSS 2.0
  • The Basic Structure
  • item Elements
  • The Simplest Possible RSS 2.0 Feed

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Try It Free
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    RSS 2.0 - The Simplest Possible RSS 2.0 Feed


    (Page 4 of 4 )

    This, really, is the key to the success of RSS 2.0. The simplest thing you need to do to make the feed validate is very uncomplicated indeed (see Example 4-2). While this isn't any help when you are trying to convey complex information, as with RSS 1.0, or if you're trying to build a complete document-centric system, as with Atom, it is very useful for many other applications.  

    Example 4-2. The simplest possible RSS 2.0 feed

    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0">

    <channel>
    <title>The Simplest Feed</title> <link>http://example.org/index.html</link> <description>The Simplest Possible RSS 2.0 Feed</description>

    <item>
    <description>Simple Simple Simple</description>
    </item>
    </channel>
    </rss>

    Chapter 10 describes many useful applications that take this a minimalist approach to using RSS 2.0--compliant feeds.

    Producing RSS 2.0 with Blogging Tools

    The vast majority of RSS 2.0 feeds are produced by weblogging tools that use templates. The most popular of these is Movable Type, written by Ben and Mena Trott, which is freely available for personal use at http://www.movabletype.org. In order to discuss a few important implementation points, Example 4-3 shows a template for Movable Type that produces an RSS 2.0 feed.

    Example 4-3. A Movable Type template for producing RSS 2.0

    <?xml version="1.0"?>
    <rss version="2.0">
    <channel>
    <title><$MTBlogName$></title> <link><$MTBlogURL$></link>

    <description><$MTBlogDescription$></description>
    <language>en-gb</language>
    <copyright>All content Public Domain</copyright> <managingEditor>ben@benhammersley.com </managingEditor> <webMaster>ben@benhammersley.com</webMaster> <docs>http://blogs.law.harvard.edu/tech/ rss</docs>
    <category domain="http://www.dmoz.org">Reference/ Libraries/Library_and_Information_ Science/Technical_Services/Cataloguing/ Metadata/RDF/Applications/RSS/</category> <generator>Movable Type/2.5</generator> <lastBuildDate><$MTDate format="%a, %d %b %Y %I:%M:00 GMT"$></lastBuildDate> <ttl>60</ttl>

    <MTEntries lastn="15">
    <item>
    <title><$MTEntryTitle encode_html="1"$></title> <description><$MTEntryExcerpt encode_html="1"$></description> <link><$MTEntryLink$></link> <comments><$MTEntryLink$></comments> <author><$MTEntryAuthorEmail$></author> <pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate>
    <guid isPermaLink="false">GUID:<$MTEntryLink$> </g<$MTEntryDate format=
    "%a%d%b%Y%I:%M"$></guid>
    </item>
    </MTEntries>
    </channel>
    </rss>

    The vast majority of this template is standard Movable Type fare. Taken from one of my own blogs, it uses the <$MT$> tags to insert information directly from the
    Movable Type database into the feed. So far, so simple.

    Two things are worth close examination. First, the date format:

      <pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate>

    Care must be taken to ensure that the format of the contents of the date fields are correctly formed. RSS 2.0 feeds require their dates to be written to comply with RFC 822--for example: Mon, 03 Jan 2002 0:00:01 GMT.

    Common errors found in RSS 2.0 feeds include missing commas, seconds values, and time zones. You must ensure these are all present because some desktop readers and aggregators aren't as forgiving as others, and many are getting less so as they develop.

    Implementation of the guid element is equally important. The RSS 2.0 standard doesn't discuss the form of the guid; it only asks the author to ensure that it is globally unique. There is no scope for the OSF GUID standard to be used within most blogging tools, so you have to formulate your own system. (I'll touch upon this again when we talk about Atom in Chapter 7.)

    For the template shown earlier, I considered various things. First, the guid's purpose is to tell applications if the entry is new or if it has changed. Second, within my own blogs I allow people to add comments to the entries. I consider this a change to the entry, so my guid must reflect this. Because this change isn't reflected in the link to the entry, the link alone isn't a good guid. So, by combining the link with the last-updated-date value, I can make a guid that is globally unique and changes when it needs to. For added measure, I add the string GUID to the front of it to prevent it from looking too much like a retrievable URL--which, of course, it isn't. Hence:

      <guid isPermaLink="false">GUID:<$MTEntryLink$> </g<$MTEntryDate format=
     
    "%a%d%b%Y%I:%M"$></guid>

    This works well as an RSS 2.0 guid, but it has one feature that might annoy: because weblog comments cause the guid to change, it also causes the item to be marked as unread in many feed aggregators. This might not be desirable behavior for you.

    Please check back next week for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Developing Feeds with RSS and Atom,"...
     

    Buy this book now. This article is excerpted from chapter four of the book Developing Feeds with RSS and Atom, written by Ben Hammersley (O'Reilly; ISBN: 0596008813). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway