目录

XML RSS


通过 RSS,可以将最新的 Web 内容从一个网站分发到世界各地数以千计的其他网站。

RSS 允许快速浏览新闻和更新。


RSS 文档示例

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

<channel>
  <title>91xjr Home Page</title>
  <link>https://www.91xjr.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>https://www.91xjr.com/xml/xml_rss.html</link>
    <description>New RSS tutorial on 91xjr</description>
  </item>
  <item>
    <title>XML Tutorial</title>
    <link>https://www.91xjr.com/xml</link>
    <description>New XML tutorial on 91xjr</description>
  </item>
</channel>

</rss>

什么是RSS?

  • RSS 代表R埃利S实施S联合组织
  • RSS 允许您联合您的网站内容
  • RSS 定义了一种共享和查看标题和内容的简单方法
  • RSS文件可以自动更新
  • RSS 允许不同站点的个性化视图
  • RSS 是用 XML 编写的

为什么使用RSS?

RSS 旨在显示选定的数据。

如果没有 RSS,用户将必须每天检查您的网站是否有新更新。对于许多用户来说这可能太耗时。通过 RSS 源(RSS 通常称为新闻源或 RSS 源),他们可以使用 RSS 聚合器(收集和整理 RSS 源的网站或程序)更快地检查您的网站。

由于 RSS 数据小且加载速度快,因此可以轻松地与手机或 PDA 等服务一起使用。

具有类似信息的网络环可以轻松地在其网站上共享数据,从而使网站变得更好、更有用。



谁应该使用 RSS?

很少更新网站的站长不需要RSS!

RSS 对于经常更新的网站很有用,例如:

  • 新闻网站 - 列出带有标题、日期和描述的新闻
  • 公司 - 列出新闻和新产品
  • 日历 - 列出即将发生的事件和重要的日子
  • 站点更改 - 列出更改的页面或新页面

RSS 的好处

以下是使用 RSS 的一些好处:

选择您的新闻
通过 RSS,您可以选择查看您想要的新闻、您感兴趣的且与您的工作相关的新闻。

删除不需要的信息
通过 RSS,您可以(最终)将想要的信息与不需要的信息(垃圾邮件)分开!

增加您的网站流量
使用RSS,您可以创建自己的新闻频道,并将其发布到互联网上!


RSS 的历史

  • 1997 - UserLand 的 Dave Winer 开发了 scriptingNews。 RSS 诞生了
  • 1999 - Netscape 开发 RSS 0.90(支持 scriptingNews)
  • 1999 - Dave Winer 开发 scriptingNews 2.0b1(其中包括 RSS 0.90 功能)
  • 1999 - Netscape 开发 RSS 0.91(其中包括 scriptingNews 2.0b1 的大部分功能)
  • 1999 - UserLand 摆脱了 scriptingNews 并仅使用 RSS 0.91
  • 1999 - Netscape 停止了 RSS 开发
  • 2000 - UserLand 发布官方 RSS 0.91 规范
  • 2000 - O'Reilly 开发了 RSS 1.0。该格式使用 RDF 和名称空间。
  • 2000 年 - UserLand 的 Dave Winer 开发了 RSS 0.92
  • 2002 年 - Dave Winer 在离开 UserLand 后开发了 RSS 2.0
  • 2003 年 - 官方 RSS 2.0 规范发布

RSS 1.0 是唯一使用 W3C RDF(资源描述框架)标准开发的版本。

RDF 背后的想法是帮助创建语义网。然而,这对于普通用户来说并不重要,但是通过使用网络标准,个人和应用程序可以更轻松地交换数据。


我应该使用什么 RSS 版本?

RSS 0.91 和 RSS 2.0 比 RSS 1.0 更容易理解。我们的教程基于 RSS 2.0。

RSS 2.0的语法规则非常简单,也非常严格。


RSS 是网络标准吗?

RSS 没有官方标准。

  • 大约 50% 的 RSS 源使用 RSS 0.91
  • 大约 25% 使用 RSS 1.0
  • 最后 25% 分为 RSS 0.9x 版本和 RSS 2.0

RSS 的工作原理

RSS 用于在网站之间共享内容。

通过 RSS,您可以向称为聚合器的公司注册您的内容。

因此,要参与其中:首先,创建一个 RSS 文档并使用 .xml 扩展名保存它。然后,将文件上传到您的网站。接下来,向 RSS 聚合器注册。聚合器每天都会在注册网站上搜索 RSS 文档,验证链接并显示有关提要的信息,以便客户可以链接到他们感兴趣的文档。

提示:阅读我们的 RSS 发布章节以查看免费的 RSS 聚合服务。


RSS 示例

RSS 文档使用自描述且简单的语法。

这是一个简单的 RSS 文档:

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

<channel>
  <title>91xjr Home Page</title>
  <link>https://www.91xjr.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>https://www.91xjr.com/xml/xml_rss.html</link>
    <description>New RSS tutorial on 91xjr</description>
  </item>
  <item>
    <title>XML Tutorial</title>
    <link>https://www.91xjr.com/xml</link>
    <description>New XML tutorial on 91xjr</description>
  </item>
</channel>

</rss>

文档中的第一行 - XML 声明 - 定义文档中使用的 XML 版本和字符编码。在本例中,文档符合 XML 1.0 规范并使用 UTF-8 字符集。

下一行是 RSS 声明,它标识这是一个 RSS 文档(在本例中为 RSS 版本 2.0)。

下一行包含 <channel> 元素。该元素用于描述 RSS 提要。

<channel> 元素具有三个必需的子元素:

  • <title> - 定义频道的标题(例如 91xjr 主页)
  • <link> - 定义频道的超链接(例如 https://www.91xjr.com)
  • <description> - 描述频道(例如免费网络构建教程)

每个 <channel> 元素可以有一个或多个 <item> 元素。

每个 <item> 元素定义 RSS 提要中的一篇文章或"story"。

<item> 元素具有三个必需的子元素:

  • <title> - 定义项目的标题(例如 RSS 教程)
  • <link> - 定义项目的超链接(例如 https://www.91xjr.com/xml/xml_rss.html)
  • <description> - 描述该项目(例如 91xjr 上的新 RSS 教程)

最后,最后两行关闭 <channel> 和 <rss> 元素。


RSS 中的注释

在 RSS 中编写注释的语法与 HTML 类似:

<!-- This is an RSS comment -->

RSS 是用 XML 编写的

由于 RSS 是 XML,因此请记住:

  • 所有元素都必须有结束标签
  • 元素区分大小写
  • 元素必须正确嵌套
  • 属性值必须始终加引号

RSS <channel> 元素

RSS <channel> 元素描述 RSS 提要。

请看下面的 RSS 文档:

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

<channel>
  <title>91xjr Home Page</title>
  <link>https://www.91xjr.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>https://www.91xjr.com/xml/xml_rss.html</link>
    <description>New RSS tutorial on 91xjr</description>
  </item>
</channel>

</rss>

如前所述,<channel> 元素描述 RSS 提要,并具有三个必需的子元素:

  • <title> - 定义频道的标题(例如 91xjr 主页)
  • <link> - 定义频道的超链接(例如 https://www.91xjr.com)
  • <description> - 描述频道(例如免费网络构建教程)

<channel> 元素通常包含一个或多个<item> 元素。每个 <item> 元素定义 RSS 提要中的一篇文章或"story"。

此外,<channel> 还有几个可选的子元素。我们将在下面解释最重要的一些。


<category> 元素

<category> 子元素用于指定 Feed 的类别。

<category> 元素使 RSS 聚合器可以根据类别对站点进行分组。

上述 RSS 文档的类别可以是:

<category>Web development</category>

<copyright> 元素

<copyright> 子元素通知有关受版权保护的材料。

上述 RSS 文档的版权可能是:

<copyright>2006 Refsnes Data as. All rights reserved.</copyright>

<image> 元素

<image> 子元素允许在聚合器呈现提要时显示图片。

<image> 元素具有三个必需的子元素:

  • <url> - 定义图片的 URL
  • <title> - 定义图片无法显示时要显示的文本
  • <link> - 定义提供频道的网站的超链接

上面的 RSS 文档的图片可以是:

<image>
  <url>https://www.91xjr.com/images/logo.gif</url>
  <title>91xjr.com</title>
  <link>https://www.91xjr.com</link>
</image>

<语言> 元素

<language> 子元素用于指定用于编写文档的语言。

<language> 元素使 RSS 聚合器可以根据语言对站点进行分组。

上述 RSS 文档的语言可以是:

<language>en-us</language>

<item> 元素

每个 <item> 元素定义 RSS 提要中的一篇文章或"story"。

请看下面的 RSS 文档:

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

<channel>
  <title>91xjr Home Page</title>
  <link>https://www.91xjr.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>https://www.91xjr.com/xml/xml_rss.html</link>
    <description>New RSS tutorial on 91xjr</description>
  </item>
</channel>

</rss>

如前所述,每个 <item> 元素定义 RSS 提要中的一篇文章或 "story"。

<item> 元素具有三个必需的子元素:

  • <title> - 定义项目的标题(例如 RSS 教程)
  • <link> - 定义项目的超链接(例如 https://www.91xjr.com/xml/xml_rss.html)
  • <description> - 描述该项目(例如 91xjr 上的新 RSS 教程)

此外,<item> 还有几个可选的子元素。我们将在下面解释最重要的一些。


<author> 元素

<author> 子元素用于指定项目作者的电子邮件地址。

笔记:为了防止垃圾邮件,一些开发人员不包含 <author> 元素。

上面 RSS 文档中的项目的作者可能是:

<author>hege@refsnesdata.no</author>

<comments> 元素

<comments> 子元素允许项目链接到有关该项目的注释。

上面 RSS 文档中该项目的注释可以是:

<comments>https://www.91xjr.com/comments</comments>

<enclosure> 元素

<enclosure> 子元素允许将媒体文件包含在项目中。

<enclosure> 元素具有三个必需属性:

  • url - 定义媒体文件的 URL
  • length - 定义媒体文件的长度(以字节为单位)
  • type - 定义媒体文件的类型

上述 RSS 文档中的项目中包含的媒体文件可以是:

<enclosure url="https://www.91xjr.com/xml/rss.mp3"
length="5000" type="audio/mpeg" />

在网络上获取您的 RSS 提要

如果其他人无法访问 RSS 文档,那么它就毫无用处。

现在是时候将您的 RSS 文件发布到网络上了。步骤如下:

1. 为您的 RSS 文件命名。请注意,该文件必须具有 .xml 扩展名。

2. 验证您的 RSS 文件

3. 将 RSS 文件上传到 Web 服务器上的 Web 目录。

4.复制小橙子RSS Logo或者XML Logo按钮到您的网络目录。

5. 将橙色小"RSS" 或"XML" 按钮放在您将向全世界提供RSS 的页面上(例如,在您的主页上)。然后添加一个链接到链接到 RSS 文件的按钮。代码看起来像这样:
<a href="https://www.91xjr.com/xml/myfirstrss.xml">
<img src="https://www.91xjr.com/xml/pic_rss.gif" 宽度="36" 高度="14">
</a>。

6. 将您的 RSS 源提交到 RSS 源目录(您可以通过 Google 或 Yahoo 获取 "RSS Feed Directories")。笔记!您的 Feed 的网址不是您的主页,而是您的 Feed 的网址,例如 "https://www.91xjr.com/xml/myfirstrss.xml"。

7. 在主要搜索引擎中注册您的提要:

8. 更新您的提要 - 注册您的 RSS 提要后,您必须确保经常更新您的内容并且您的 RSS 提要始终可用。


我可以自己管理我的 RSS 源吗?

确保 RSS 源按照您想要的方式工作的最佳方法是自行管理。

然而,这可能非常耗时,尤其是对于有大量更新的页面。

另一种方法是使用第三方自动 RSS。


自动RSS

对于只需要为个人网站提供 RSS 源的用户,提供内置 RSS 服务的一些最受欢迎的博客(网络日志)管理器包括:


RSS 阅读器

RSS 阅读器用于阅读 RSS 源!

RSS 阅读器可用于许多不同的设备和操作系统。

有很多不同的 RSS 阅读器。有些作为 Web 服务工作,有些仅限于 Windows(或 Mac、PDA 或 UNIX):

  • 相当RSS- 开源、跨平台的 RSS/Atom 新闻源阅读器
  • 提要阅读器- 简单直接的提要阅读器,可轻松处理大量提要

提示:大多数浏览器都有内置的 RSS 阅读器。如果您访问提供 RSS 源的网站,您将看到 RSS 图标RSS在地址栏或工具栏中。单击该图标可查看不同提要的列表。选择您想要阅读的提要。


我有一个 RSS 阅读器。怎么办?

点击小RSS Logo或者XML Logo您要阅读的 RSS 提要旁边的按钮。复制您在浏览器窗口中获得的 URL 并将其粘贴到 RSS 阅读器中。


RSS 参考

<channel> 元素

"Element" 列中的链接指向有关每个特定元素的更多信息。

Element Description
<category> Optional. Defines one or more categories for the feed
<cloud> Optional. Register processes to be notified immediately of updates of the feed
<copyright> Optional. Notifies about copyrighted material
<description> Required. Describes the channel
<docs> Optional. Specifies a URL to the documentation of the format used in the feed
<generator> Optional. Specifies the program used to generate the feed
<image> Optional. Allows an image to be displayed when aggregators present a feed
<language> Optional. Specifies the language the feed is written in
<lastBuildDate> Optional. Defines the last-modified date of the content of the feed
<link> Required. Defines the hyperlink to the channel
<managingEditor> Optional. Defines the e-mail address to the editor of the content of the feed
<pubDate> Optional. Defines the last publication date for the content of the feed
<rating> Optional. The PICS rating of the feed
<skipDays> Optional. Specifies the days where aggregators should skip updating the feed
<skipHours> Optional. Specifies the hours where aggregators should skip updating the feed
<textInput> Optional. Specifies a text input field that should be displayed with the feed
<title> Required. Defines the title of the channel
<ttl> Optional. Specifies the number of minutes the feed can stay cached before refreshing it from the source
<webMaster> Optional. Defines the e-mail address to the webmaster of the feed

<item> 元素

Element Description
<author> Optional. Specifies the e-mail address to the author of the item
<category> Optional. Defines one or more categories the item belongs to
<comments> Optional. Allows an item to link to comments about that item
<description> Required. Describes the item
<enclosure> Optional. Allows a media file to be included with the item
<guid> Optional. Defines a unique identifier for the item
<link> Required. Defines the hyperlink to the item
<pubDate> Optional. Defines the last-publication date for the item
<source> Optional. Specifies a third-party source for the item
<title> Required. Defines the title of the item