当前位置: 首页 > 网络学院 > XML相关教程 > RSS > RSS 语法

RSS
RSS 介绍
RSS 历史
RSS 语法
RSS <channel> 元素
RSS <item> 元素
RSS 发布 Feed
RSS 解读 Feed

RSS 语法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 568 ::
收藏到网摘: n/a

The syntax rules of RSS 2.0 are very simple and very strict. The rules are very easy to learn, and very easy to use.
RSS 2.0 的语法很简单,也很严格。这些规则很容易学习,也很容易使用。


How RSS Works
RSS 如何运行

RSS is used to share content between websites.
RSS 用于在网站间分享信息。

With RSS, you register your content with companies called aggregators.
使用 RSS,您在名为聚合器的公司注册您的内容。

So, to be a part of it: First, create an RSS document and save it with an .xml extension. Then, upload the file to your website. Next, register with an RSS aggregator. Each day the aggregator searches the registered websites for RSS documents, verifies the link, and displays information about the feed so clients can link to documents that interests them.
作为他的一部分,创建一个 RSS 文档,然后使用 .xml 后缀来保存它。然后把此文件上传导您的网站。接下来,通过一个 RSS 聚合器来注册。每天,聚合器都会到被注册的网站搜索 RSS 文档,校验其链接,并显示有关 feed 的信息,这样客户就能够链接到使他们产生兴趣的文档。

Tip: Read our RSS Publishing chapter to view free RSS aggregation services.
提示:请在 RSS 发布 这一节浏览免费的 RSS 聚合器服务。


An Example RSS document
RSS 文档实例

RSS documents use a self-describing and simple syntax.
RSS文档使用一种简单的自我描述简单语法。

Let's look at a simple RSS document:
让我们看一个简单的 RSS 文档:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>W3Schools Home Page</title>
<link>http://www.w3schools.com</link>
<description>Free web building tutorials</description>

<item>
<title>RSS Tutorial</title>
<link>http://www.w3schools.com/rss</link>
<description>New RSS tutorial on W3Schools</description>

</item>
<item>
<title>XML Tutorial</title>
<link>http://www.w3schools.com/xml</link>
<description>New XML tutorial on W3Schools</description>

</item>
</channel>
</rss>

The first line in the document - the XML declaration - defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set.
文档中的第一行:XML 声明 - 定义了文档中使用的 XML 版本和字符编码。此例子遵守 1.0 规范,并使用 ISO-8859-1 (Latin-1/West European) 字符集。

The next line is the RSS declaration which identifies that this is an RSS document (in this case, RSS version 2.0).
下一行是标识此文档是一个 RSS 文档的 RSS 声明(此例是 RSS version 2.0)。

The next line contains the <channel> element. This element is used to describe the RSS feed.
下一行含有 <channel> 元素。此元素用于描述 RSS feed。

The <channel> element has three required child elements:
<channel> 元素有三个必需的子元素:

  • <title> - Defines the title of the channel (e.g. ruanchen Home Page)
    <title>-定义了channel的标题(如:ruanchen主页)
  • <link> - Defines the hyperlink to the channel (e.g. http://www.ruanchen.com)
    <link>-定义了到channel的超链接(如:http://www.ruanchen.com
  • <description> - Describes the channel (e.g. Free web building tutorials) 
    <description>-描述了channel(如:免费的网络建设教程)

Each <channel> element can have one ore more <item> elements.
每个 <channel> 元素可拥有一个或多个 <item> 元素。

Each <item> element defines an article or "story" in the RSS feed.
每个 <item> 元素可定义 RSS feed 中的一篇文章或 "story"。

The <item> element has three required child elements:
<item> 元素拥有三个必需的子元素:

Finally, the two last lines close the <channel> and <rss> elements.
最后,后面的两行关闭 <channel> 和 <rss> 元素。


Comments in RSS
RSS 的注释

The syntax for writing comments in RSS is similar to that of HTML:
在 RSS 中书写注释的语法与 HTML 的语法类似:

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

 


RSS is Written in XML
使用 XML 编写 RSS

Because RSS is XML, keep in mind that:
因为RSS是XML,所以要记住:

  • All elements must have a closing tag
    所有元素必须包含一个结束标签
  • Elements are case sensitive
    元素要区分大小写
  • Elements must be properly nested
    元素必须被正确地嵌套
  • Attribute values must always be quoted
    属性值必须包含引号

评论 (0) All

登陆 | 还没注册?