Standard Feed Formats


In order for a feed to be useful to the general public, it needs to be in a format their software already understands; the two most common types of formats are RSS and Atom. Both types are already supported by a wide range of aggregators and are produced by numerous blogs and news sites.

A brief introduction to the feeds is presented here, with sample code from each of the major formats use today. Don't get bogged down reading into the details; the next two chapters take a more in-depth look.

There are more versions of both the RSS and Atom specifications than are presented here, but this book concentrates on the versions most often used.

RSS

One of the most popular formats for syndicating information is RSS. Currently, three versions are widely used: 0.91, 1.0, and 2.0, all of which present varying levels of compatibility. Most aggregators, whether stand-alone client or web-based, can support all three versions, so it really comes down to what you and your users need. As with any project, examine the specific capabilities of your users before making any decisions. (For example, if this is for a corporate intranet, examine the software and versions common throughout the organization. Frequently, Information Technology departments run a version or two ahead of the rest of the organization, and hence the target market for your feed must be closely examined.)

Note 

For all three revisions of the RSS schema, the height and width elements for an image are considered optional. However, note that the assumed values are a width of 88 px and a height of 31px (this is approximately the size of those "web buttons" you see on various sites promoting software or other sites).

RSS 0.91

RSS 0.91 is commonly used by many blogs and news sites. It allows basic textual information syndication, without too many required tags. For a basic news site, this allows a base channel tag to describe the site (name, description, language, webmaster, copyright, logo, and so on), and then an item tag for each individual story containing further information (title, link, description). The link in each item should be to the page containing the story itself, not the root page for the site.

 <?xml version="1.0"?> <!DOCTYPE rss SYSTEM "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91">   <channel>     <language>en</language>     <title>Example News.com</title>     <description>News and commentary from the example community.</description>     <link>http://www.example.com/</link>     <image>       <title>Wrox News .com</title>       <link>http://www.example.com/</link>       <url>http://www.example.com/pics/button.png</url>     </image>     <item>       <title>Feed usage up 1000%!</title>       <link>http://www.example.com/story2/index.html</link>       <description>Feed usage has increased a dramatic 1000% in the past 48hrs alone, this may...</description>     </item>     <item>       <title>RSS Feed Goes Live!</title>       <link>http://example.org/story1/index.html</link>       <description>Example.com is proud to announce the launch of our premier RSS service...</description>     </item>   </channel> </rss> 

RSS 1.0

The 1.0 version of the specification changed to allow for forward flexibility by adding namespaces to the document; these changes presented a few incompatibilities with previous versions of RSS. The goal with version 1.0 of the specification was to lock down core functionality, and allow everything else to be expanded with new namespaces.

 <?xml version="1.0"?> <rdf:RDF   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"   xmlns="http://purl.org/rss/1.0/">   <channel rdf:about="http://www.example.com/xml/news.rss">     <title>Example News.com</title>     <link>http://example.com/news</link>     <description> News and commentary from the example community.</description>     <image rdf:resource="http://www.example.com/pics/button.png" />     <items>       <rdf:Seq>         <rdf:li resource="http://www.example.com/story1/index.html" />         <rdf:li resource="http://www.example.com/story1/index.html" />       </rdf:Seq>     </items>   </channel>   <image rdf:about="http://www.example.com/pics/button.png">     <title>Example.com promotional button</title>     <link>http://www.example.com</link>     <url>http://www.example.com/pics/button.png</url>   </image>   <item rdf:about="http://example.org/story2/index.html">     <title> Feed usage up 1000%!</title>     <link> http://example.org/story2/index.html </link>     <description>       Feed usage has increased a dramatic 1000% in the past 48hrs alone, this       may...     </description>   </item>   <item rdf:about="http://www.example.com/story1/index.html">     <title>RSS Feed Goes Live!</title>     <link>http://www.example.com/story1/index.html</link>     <description>       Example.com is proud to announce the launch of our premier RSS service...     </description>   </item> </rdf:RDF> 

RSS 2.0

This is where the real fun begins. The biggest change you will notice is with the introduction of many much-needed tags in the item element, including enclosure (to attach a file with the specific item), author, category, comments, pubDate, and so on. These additions will probably serve to make RSS 2.0 the schema of choice if it is available to your audience.

This example builds on the one presented for version 0.91 by adding a third item and fleshing out the information provided. Because the information permitted in RSS 0.91 is a subset of 2.0, it is a good idea to provide both 0.91 and 2.0 feeds if you decide to go with 2.0.

 <rss version="2.0">   <channel>     <language>en</language>     <title>Example News.com</title>     <description>News and commentary from the cross-platform scripting       community.</description>     <link>http://www.wroxnews.com/</link>     <image>       <title>Example News.com</title>       <link>http://www.wroxnews.com/</link>       <url>http://www.wroxnews.com/pics/button.png</url>     </image>     <item>       <title>Feed usage up 1000%!</title>       <link>http://www.wroxnews.com/story2/index.html</link>       <description>Feed usage has increased a dramatic 1000% in the past 48hrs         alone, this may...</description>      <enclosure url="http://www.wroxnews.com/feedusage.pdf" length="38642"       type="application/pdf" />     </item>     <item>       <title>RSS Feed Goes Live!</title>       <link>http://wroxnews.org/story1/index.html</link>       <description>Wroxnews.com is proud to announce the launch of our premier RSS         service...</description>      <enclosure url="http://www.wroxnews.com/feedlive.pdf" length="28646"       type="application/pdf" />     </item>   </channel> </rss> 

Expanding RSS

RSS provides a mechanism for adding tags to an RSS document. This can be done by adding additional XML namespaces to the document in the rss tag. The syntax is relatively simple. For example:

 <rss version="2.0"xmlns:cc="http://backend.userland.com/creativeCommonsRssModule"> 

This defines the document as being RSS 2.0, adds an additional namespace (cc) to the document, and indicates where to find more information about the namespace. In this case, the cc namespace is for the Creative Commons license. Adding this tag will allow inclusion of several cc tags to define the copyright restrictions (or lack thereof) placed on the document. To declare a tag within the cc namespace, just prepend the tag with cc. For example:

 <item>   <title>RSS Feed Goes Live!</title>   <link>http://wroxnews.org/story1/index.html</link>   <description>Wroxnews.com is proud to announce the launch of our premier RSS service...</description>   <cc:license>http://www.creativecommons.org/licenses/by-nc/1.0<cc:license>  </item> 

This extensibility allows feed creators to include any desired information with their feed in a recognizable way. Before defining your own namespace, look at the ones already available. Using the same namespaces as other similar sites will allow users to consume your feed more easily (because their aggregation software will likely already support your added namespace).

Note 

You will often see namespaces referencing a URL beginning with http://purl.org/. Purl offers a Permanent URL for resources that might move around in the future (saving everyone the headache of changing their links, as well as providing a short URL in place of a cumbersome one).

Atom 0.3

Atom was created to resolve some perceived ambiguities within the RSS specification (RSS 2.0 was declared to be the final version, so these issues can't be resolved by releasing new versions of RSS). This section covers Atom 0.3, which is the latest version as of print time, but is still in beta.

 <?xml version="1.0" encoding="utf-8"?> <feed version="0.3" xmlns="http://purl.org/atom/ns#">   <title>dive into mark</title>   <link rel="alternate" type="text/html" href="http://diveintomark.org/"/>   <modified>2003-12-13T18:30:02Z</modified>   <author>     <name>Mark Pilgrim</name>   </author>   <entry>     <title>Atom 0.3 snapshot</title>     <link rel="alternate" type="text/html"      href="http://diveintomark.org/2003/12/13/atom03"/>     <id>tag:diveintomark.org,2003:3.2397</id>     <issued>2003-12-13T08:29:29-04:00</issued>     <modified>2003-12-13T18:30:02Z</modified>   </entry> </feed> 

As you can see, although the Atom specification may use different terms for several of the elements, there really isn't too large a difference between the specifications. Personally, I appreciate the addition of the modified tag to remove some of the ambiguity associated with posts that were later updated. That being said, I prefer the date format used in the RSS feeds. Beyond that, which feed formats you decide to produce is entirely dependent on what your user base desires or is able to interpret. When unsure, produce both. The full Atom spec, for versions 0.1–0.3, is available in Appendix B.

Note 

The Atom 0.3 specification calls for the Content-Type header to be set to application/atom+xml. However, while I am debugging feeds with a browser, I find it convenient to set the Content-Type header to text/xml, because most browsers will attempt to locate an external registered handler for application/atom+xml, but will display text/xml themselves.




Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
ISBN: 764589547
EAN: N/A
Year: 2006
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net