【问题标题】:Extending RSS format with more fields?用更多字段扩展 RSS 格式?
【发布时间】:2011-10-21 20:28:41
【问题描述】:

我有一个需要为其创建 RSS 提要的网站。是否有向 RSS 提要添加自定义字段的标准格式?例如,我想在我的 RSS 提要中添加一个“位置”元素。我有一些合作伙伴希望使用这些提要并能够使用特定于我的网站的自定义字段。

对于当前的 RSS 2.0 格式,这些是 RSS 2.0 规范中可用的包含字段:

<?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>
    <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>

如果我想添加更多元素以供合作伙伴使用,以便他们可以随意使用和解析它们,该怎么办?同时,如果他们将我的 RSS 提要添加到其中,我不想破坏 RSS 阅读器。关于处理这个问题的最佳方法有什么想法吗?

【问题讨论】:

    标签: xml content-management-system rss rss2


    【解决方案1】:

    根据RSS 2.0 Specification则:

    "RSS 起源于 1999 年,一直致力于做一个简单、易上手的 了解格式,目标相对温和。变成了一个之后 流行的格式,开发人员希望使用定义的模块来扩展它 在 W3C 指定的命名空间中。

    RSS 2.0 遵循一个简单的规则添加了该功能。 RSS 提要可以 包含本页未描述的元素,仅当这些元素 在命名空间中定义。”

    查看文章Extending RSS 2.0 With Namespaces,它向您展示了如何执行此操作。文章中的一个示例显示了作者将一些自定义博客字段添加到他们的提要中:

     <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>
    

    【讨论】:

      【解决方案2】:

      您可以使用任何您想要的元素来扩展 RSS 消息,而 RSS 阅读器区分标准元素和扩展的方式是扩展位于命名空间中。这样,标准阅读器可以轻松阅读标准元素并忽略扩展。

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

      RSS 提要可能包含此页面上未描述的元素,前提是这些元素已在命名空间中定义。

      【讨论】:

        猜你喜欢
        • 2023-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多