开发者

Extending RSS format with more fields?

I have a website that I need to create an RSS feed for. Is there a standard format for adding custom fields to an RSS feed? I would like to add a "location" element to my RSS feeds for example. I have some partners that would like to consume the feeds and be able to use the custom fields specific to my website.

For the current RSS 2.0 format, these are the included fields available from the RSS 2.0 specifications:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>RSS Example</title>
    <description>This is an example of an RSS feed</description>
    <link>http://www.domain.com/link.htm</link>
    <lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
    <pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
    <language>en-us</language>
    <copyright>Copyright 2002, Spartanburg Herald-Journal</copyright>
    <managingEditor>geo@herald.com (George Matesky)</managingEditor>
    <webMaster>betty@herald.com (Betty Guernsey)</webMaster>
    <category>Newspapers</category>
    <generator>MightyInHouse Content System v2.3</generator>
    <开发者_如何学C;docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <image>
      <title>Something</title>
      <url>http://something.com/image.jpg</url>
      <link>http://something.com</link>
      <description>This is something</description>
    </image>
    <rating>(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~000 1))</rating>
    <item>
      <title>Item Example</title>
      <description>This is an example of an Item</description>
      <link>http://www.domain.com/link.htm</link>
      <guid> 1102345</guid>
      <pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
      <author>lawyer@boyer.net (Lawyer Boyer)</author>
      <category>Grateful Dead</category>
      <comments>http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290</comments>
      <enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />
      <source url="http://www.tomalak.org/links2.xml">Tomalak's Realm</source>
    </item>
  </channel>
</rss>

What if I wanted to add more elements to make them available for partners so they can consume and parse them as they please? At the same time, I do not want to break RSS readers if they add my RSS feed to it. Any idea on the best way to handle this?


According to the RSS 2.0 Specification then:

"RSS originated in 1999, and has strived to be a simple, easy to understand format, with relatively modest goals. After it became a popular format, developers wanted to extend it using modules defined in namespaces, as specified by the W3C.

RSS 2.0 adds that capability, following a simple rule. A RSS feed may contain elements not described on this page, only if those elements are defined in a namespace."

Check out the article Extending RSS 2.0 With Namespaces which shows you how to do this. An example from the article shows the author adding some custom blog fields to their feed:

 <rss version="2.0"
     xmlns="http://backend.userland.com/rss2"
     xmlns:blogChannel="http://backend.userland.com/blogChannelModule">
 <channel>
  <title>Scripting News</title>
  <link>http://www.scripting.com/</link>
  <blogChannel:blogRoll>http://radio.weblogs.com/ ... /file.opml</blogChannel:blogRoll>
  <blogChannel:mySubscriptions>http://ra ... /file.opml</blogChannel:mySubscriptions>
  <blogChannel:blink>http://inessential.com/</blogChannel:blink>
  .
  .
  .
 </channel>
 </rss>


You can extend the RSS message with any elements that you want, and the way that the RSS readers distinguish the standard elements from extensions is that the extensions is in a namespace. That way a standard reader can easily read the standard elements and ignore the extensions.

http://cyber.law.harvard.edu/rss/rss.html#extendingRss:

A RSS feed may contain elements not described on this page, only if those elements are defined in a namespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜