RSS2.0 规范
RSS 2.0 规范
先上一个RSS2.0的例子,然后下面再一一做说明:
<?xml version="1.0"?> <rss version="2.0"> <channel> <title>Liftoff News</title> <link>http://liftoff.msfc.nasa.gov/</link> <description>Liftoff to Space Exploration.</description> <language>en-us</language> <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate> <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>Weblog Editor 2.0</generator> <managingEditor>editor@example.com</managingEditor> <webMaster>webmaster@example.com</webMaster> <item> <title>Star City</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link> <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.</description> <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid> </item> <item> <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm">partial eclipse of the Sun</a> on Saturday, May 31st.</description> <pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid> </item> <item> <title>The Engine That Does More</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link> <description>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</description> <pubDate>Tue, 27 May 2003 08:37:32 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid> </item> <item> <title>Astronauts' Dirty Laundry</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link> <description>Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</description> <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid> </item> </channel> </rss>
必要元素
下面是必须包含在频道(channel)节点的列表,每一个都有一个简单的描述、一个例子、应该出现的位置和更详细描述的超链接。如下表所示:
元素 | 描述 | 例子 |
---|---|---|
title | channel的名称。如果你有一个与你的RSS文件内容一致的HTML网站,你的title元素值应该与你的网站的标题相同。 | GoUpstate.com News Headings |
link | 该频道的网站的URL | http://www.goupstate.com/ |
description | 关于该频道的描述 | The latest news from GoUpstate.com |
可选的元素
元素 | 描述 | 例子 |
---|---|---|
language | 使用的语言。 | en-us |
copyright | 版权声明 | Copyright 2002, Spartanburg Herald-Journal |
managingEditor | 负责编辑内容人员的电子邮箱地址。 | geo@herald.com |
webMaster | 网站管理者的电子邮箱地址 | betty@herald.com |
pubDate | 内容的发布时间 | Sat, 07 Sep 2002 00:00:01 GMT |
lastBuildDate | 最后更新时间 | Sat, 07 Sep 2002 09:42:31 GMT |
category | 指定该频道所属的一个或多个分类。遵循与item级category元素相同的规则。 | <category>Newspapers</category> |
generator | 生成该频道的程序名称 | MightyInHouse Content System v2.3 |
docs | 指向RSS文件中使用的格式文档的URL,它可能是指向这一页的指针。这是给25年后可能在Web服务器上偶然发现RSS文件并想知道它是什么人的。 | http://blogs.law.harvard.edu/tech/rss |
cloud | 允许进程向云注册用于收到频道的更新通知,为RSS提要实现轻量级发布订阅协议 | <cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/> |
ttl | ttl是Time to live的缩写。它指示cache的有效保存时间。 | <ttl>60</ttl> |
image | 与频道一起显示的图片地址 | |
rating | 该频道的统计图片地址 | |
textInput | 指定一个textbox与该频道一起显示 | |
skipHours | 告诉使用者哪些时段是可以忽略的 | |
skipDays | 告诉使用着哪些天是可以忽略的 |
<channel>的子节点<image>
<image>是<channel>的可选元素, 它包含三个必需的和三个可选的子元素。
<url>是代表频道的GIF、JPEG或PNG图像的URL。
<title>描述图像,当通道以HTML方式呈现时,它用于HTML填充<img>标记的ALT属性。
<link>是站点的URL,当呈现频道时,图像是指向站点的链接。(注意,实际上,图像<title>和<link>应该与频道的<title>和<link>具有相同的值。
可选元素包括<width>和<height>,以像素为单位表示图像的宽度和高度。<description>包含包含在HTML呈现中围绕图像形成的链接的标题属性中的文本。
width的最大值为144,默认为88,height的最大值为400,默认为31
<channel>的子节点<cloud>
<cloud>是一个可选的<channel>子节点。它指定一个可以支持rssCloud接口的web服务,rssCloud接口可以用HTTP-POST,XML-RPC或SOAP1.1实现。它的目的是允许通知注册为cloud的进程频道被更新,从而实现一个轻量级的发布订阅协议。
<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc"/>
在这个例子中,为了请求频道通知,你需要发送一个XML-RPC消息到rpc.sys.com的80端口,路径为/RPC2。调用的过程为myCloud.rssPleaseNotify。
<channel>的子节点<ttl>
<ttl>是一个可选的<channel>子节点。ttl是time to live的缩写。它表示频道在被刷新前应该被缓存的时间。这使得rss源可以被一个支持文件共享的网络所管理,例如Gnutella
<ttl>60</ttl>
<channel>的子节点<textInput>
<textInput>是<channel>的可选的子节点,<textInput>包含四个子节点。
<title>--提交按钮的标签
<description>--该文本输入区的描述
<name>--文本输入区的名称
<link>--处理文本输入的CGI脚本的URL
使用<textInput>的目的有些神秘。你可以用它提供一个搜索引擎输入框,或者让读者提供反馈信息。大部分聚合器都直接忽略该节点。
Item的节点
节点 | 描述 | 例子 |
---|---|---|
title | item的标题 | Venice Film Festival Tries to Quit Sinking |
link | item的URL | http://www.kaifaxueyuan.com/basic/rss/rss-specification.html |
description | item概要 | 开发学院(www.kaifaxueyuan.com)提供最全最新的编程技术基础教程 |
author | 作者的email地址 | oprah@oxygen.net |
category | item可以包含在一个或多个分类中 | Simpsons Characters |
comments | 与item相关的评论的地址 | http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290 |
enclosure | 附加的媒体对象 | |
guid | 可以唯一确定item的字符串 | http://inessential.com/2002/09/01.php#a2 |
pubDate | item发布的时间 | Sun, 19 May 2002 15:21:36 GMT |
source | rss频道来源 | Quotes of the Day |
<item>的子节点<source>
<source>是<item>的可选节点。它的值是item来自的rss频道的名称,从item的title衍生而来。它有一个必须包含的属性url,该属性链接到XML序列化源。格式如下所示:
<source url="http://static.userland.com/tomalak/links2.xml">Tomalak's Realm</source>
该节点的作用是提高连接的声望,进一步推广新闻项目的源头。它可以用在聚合器的Post命令中。当从聚合器通过webblog访问一个item时,<source>能够自动被生成。
<item>的子节点<enclosure>
<enclosure>是<item>的可选节点。它有三个必要的属性。url属性指示enclosure的位置,length指出它的字节大小,type属性指出它的标准MIME类型。url必须为一个http url。
<enclosure url=http://www.scripting.com/mp3s/weatherReportSuite.mp3 length="12216320" type="audio/mpeg" />
<item>的子节点<category>
<category>是<item>的可选节点。它有一个可选属性或域,该属性是一个用来定义分类法的字符串。该节点的值是一个正斜杠分割的字符串,它用来在指定的分类法中识别一个分级位置(hierarchic location)。处理器可以为分类的识别建立会话。(Processors may establish conventions for the interpretation of categories)下面有两个例子:
<category>Grateful Dead</category> <category domain="http://www.fool.com/cusips">MSFT</category>
你可以根据你的需要为不同的域(domain)包含很多category节点,并且可以在相同域的不同部分拥有一个前后参照的item。
<item>的子节点<pubDate>
<pubDate>是<item>的可选节点。它的值代表item的发布日期。如果它是一个尚未开始的日期,聚合器在整个日期之前可以选择不显示该item。例子如下:
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
<item>的子节点<guid>
<guid>是<item>的可选节点。guid是globally unique identifier的缩写。它是一个可以唯一识别item的字符串。当item发布之后,聚合器可以选择使用该字符串判断该item是否是新的。
<guid>http://some.server.com/weblogItem3207</guid>
guid没有特定的语法规则,聚合器必须将他们看作一个字符串。生成具有唯一性的字符串guid取决于种子的源头。
如果guid节点有isPermaLink属性,并且值为真,读取器就会认为它是item的permalink。permalink是一个可在web浏览器中打开的url链接,它指向<item>节点所描述的全部item。
<guid isPermaLink="true">http://inessential.com/2002/09/01.php#a2</guid>
isPermaLink是可选属性,默认值为真。如果值为假,guid将不会被认为是一个url或指向任何对象的url。
<item>的子节点<comment>
<comment>是<item>的可选节点。如果出现,它指向该item评论的url。
<comments>http://rateyourmusic.com/yaccs/commentsn/blogId=705245&itemId=271</comments>
<item>的子节点<author>
<author>是<item>的可选节点。它是item的作者的email。对于通过rss传播的报纸和杂志,作者可能是写该item所描述的文章的人。对于聚集型webblogs,作者可能不是责任编辑或站长。对于个人维护的webblog,忽略<author>节点是有意义的。
<author>lawyer@boyer.net (Lawyer Boyer)</author>