谢谢你留下时光匆匆
RSS Feed xml格式模版与标签归纳

最近在做的几个个人项目,都会遇到RSS feed的开发,这里对rss开发相关的资料做一个汇总,方便以后开发使用。

模版

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<channel>
  <title>频道的名称</title>
  <link>https://www.w3schools.com</link>
  <description><![CDATA[频道的描述]]></description>
    
  <item>
    <title>第一篇文章的标题</title>
    <link>https://www.w3schools.com/xml/xml_rss.asp</link>
    <description><![CDATA[第一篇文章的内容]]></description>
  </item>
    
  <item>
    <title>第二篇文章的标题</title>
    <link>https://www.w3schools.com/xml</link>
    <description><![CDATA[第二篇文章的内容]]></description>
  </item>
    
</channel>

</rss>

这里主要借鉴了XML RSS - W3School。

标签(字段)含义

<channel>下标签

标签选填与否标签说明例子
title必填RSS源的名称GoUpstate.com News Headlines
link必填RSS信息源所在网页http://www.goupstate.com/
description必填这个RSS源的介绍The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.
language选填该RSS源使用的语言,可以参考 HTML 语言代码参考手册(W3School)查找具体的语言代码zh
copyright选填文章的版权说明Copyright 2002, Spartanburg Herald-Journal
managingEditor选填该RSS源内容方面负责人的Email地址[email protected] (George Matesky)
webMaster选填该RSS源技术方面负责人的Email地址[email protected] (Betty Guernsey)
pubDate选填该RSS源发布的时间,需要符合 RFC 822 格式Sat, 07 Sep 2002 0:00:01 GMT
lastBuildDate选填该RSS源最后更新的时间Sat, 07 Sep 2002 9:42:31 GMT
category选填该RSS源所属的分类(可添加多项)Newspapers
generator选填生成该RSS的程序MightyInHouse Content System v2.3
docs选填该RSS源格式说明的网页URL地址http://backend.userland.com/rss
cloud选填Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. More info here.
ttl选填ttl是time to live的缩写,用于说明该RSS保持即时性的时间,即多长时间内(用分钟数表示)无需再从该RSS源拉取新的更新。60
image选填用于的展示该RSS源的GIF, JPEG 以及 PNG 地址
textInput选填Specifies a text input box that can be displayed with the channel. More info here.
skipHours选填A hint for aggregators telling them which hours they can skip. More info here.
skipDays选填A hint for aggregators telling them which days they can skip. More info here.

<Item>下标签

标签选填与否标签说明例子
title必填文章的标题Venice Film Festival Tries to Quit Sinking
link必填文章的原文链接http://www.nytimes.com/2002/09/07/movies/07FEST.html
description必填文章内容Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.
guid选填文章的idhttp://inessential.com/2002/09/01.php#a2
author选填文章作者的Email地址[email protected]
pubDate选填文章发布的时间Sun, 19 May 2002 15:21:36 GMT
category选填该篇文章所属的分类(可添加多项)Simpsons Characters
source选填该篇文章的RSS源MSFT
comments选填该篇文章评论区的URL网址http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
enclosure选填该篇文章附加的媒体资源

CDATA

对于<description>标签里面的内容,我们最好加上CDATA标识,以避免产生解析上的歧义与错误。

关于的作用,在Stack Overflow上有这样的解释

A CDATA section is “a section of element content that is marked for the parser to interpret as only character data, not markup.”

– What does < ![CDATA[]] > in XML mean?

翻译过来就是,被标记为CDATA的section,会被解析器解析为纯字符串文本,而非xml代码块。