论坛首页 Java企业应用论坛

RSS标准混乱,哪种RSS解析组件工具最适合解析RSS

浏览 1307 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-02-07  

       针对目前市场流行的RSS格式很多。RSS 1.0和 2.0 格式所包含的核心信息相同,但其结构不一样。 RSS 1.0 的根元素是 rdf:RDF,而 RSS 2.0 的根元素是 rss。rss 还包含一个强制版本属性用以表示所用的RSS的准确格式(可能的值包括:0.91, 0.94 等)。另一个主要差别是 RSS 1.0 文档有名字空间限定,RSS 2.0 的文档就没有。不管怎样,包含在两个文档中的信息本质上是一样的。

       两个版本都包含 channel 元素,而 channel 元素又包含三个必须的元素:title、description 和 link,其代码如下:

<channel>
<title><!-- channel 的标题 --></title>
<description><!-- 简要描述 --></description>
<link><!-- channel 的 URL --></link>
<!-- 可选/可扩展元素 -->
</channel>
        除了这些必须的元素外,RSS 1.0 还定义了三个附加元素:image、items 和 textinput,其中,image 和 textinput 是可选的。另一方面,RSS 2.0 提供了 16 个附加元素,其中也包括 image、items 和 textinput,此外还有 language、copyright、managingEditor、pubDate 和 category。RSS 1.0 允许通过定义在单独的 XML 名字空间中的可扩展元素来创建这种类型的元数据。
   这两种格式在结构上的主要区别必须要看其 item、image 和 textinput 节点的表示形式。RSS 1.0 中,channel 元素包含对 item、image 和 textinput 节点的引用,这些节点存在于 channel 节点本身之外。这样在 channel 和 所引用的节点之间建立了一种 RDF 关联。如 Figure 1 所示,channel 元素与一个 image 元素以及两个 item 元素关联。RSS 2.0 中,item 元素只是在 channel 元素中连续排放(如 Figure 2 所示)。item 元素包含实际的新闻项信息。item 的结构在两个版本中是相同的。item 元素通常包含 title、link 和 description 元素,如下代码所示:
<item>
<title><!-- 项标题 --></title>
<link><!-- 项 URL --></link>
<description><!-- 简要描述 --></description>
<!-- 可选的/可扩展的元素 -->
</item>
         在 RSS 1.0 中,title 和 link 是必须的,description 是可选的。而在 RSS 2.0 中,title 或 description 必须提供其中的一个;其它均可选。这些只是定义在 RSS 1.0 中的 item 元素。RSS 2.0 提供几个其它可选元素,其中有 author、category、comments、enclosure、guid、pubDate 和 source。RSS 1.0 获取这样的元数据是通过定义在单独的 XML 名字空间中称为 RSS 模块的可扩展元素来实现的。例如,在 Figure 1 中,item 的日期是用 Dublic Core 模块的 <dc:date> 元素表示的。

有关不同格式的完整信息请参考 RSS 1.0 和 2.0 规范。

        Atom 乃一项目的名字,主要是开发一个新的网志摘要格式以解决目前 RSS 存在的问题(混乱的版本号,不是一个真正的开放标准,表示方法的不一致,定义贫乏等等)。Atom 希望提供一个清晰的版本以解决每个人的需要,其设计完全不依赖于供货商,任何人都可以对之进行自由扩展,完整详细说明。
当今许多 Blog 引擎已经支持当前的摘要格式。Figure 3 是一个Atom 0.3 提要例子,它与前述 Figure 1 及 Figure 2 RSS 提要等同。注意 Atom 提要用名字空间限定的,但它不使用 RDF。这使得 Atom 和 RSS 1.0 及 RSS 2.0 在某些地方有相似之处。Atom 在未来是否能被接受,人们拭目以待。
     除了定义新的摘要格式之外,Atom 还希望定义一个标准的档案文件格式和一个标准的网志编辑 API(Atom API)。有关 Atom 详细规范以及其它 Atom 资源请访问 The Atom Project。

     准备采用RSS做一个阅读器软件呢,但是发现RSS的解析组件很多,但是多数局限性很大。如RssLibJ不能解析RSS2.0版本。紧接着测试其他的RSS工具也具有这样那样的问题。最终决定采用Apache的FeeParser解析RSS。根据Feeparser的官方网站(http://commons.apache.org/dormant/feedparser/)提供信息如下:

 

原文章:

      Jakarta FeedParser is a Java RSS/Atom parser designed to elegantly support all versions of RSS (0.9, 0.91, 0.92, 1.0, and 2.0), Atom 0.5 (and future versions) as well as easy ad hoc extension and RSS 1.0 modules capability.

FeedParser was the parser API designed by Kevin Burton for NewsMonster and has been donated to the ASF in order to continue development.

FeedParser differs from most other RSS/Atom parsers in that it is not DOM based but event based (similar to SAX). Instead of the low level startElement() API present in SAX, we provide higher level events based on feed parsing information.

Events are also given to the caller independent of the underlying format. This is accomplished with a Feed Event Model that isolates your application from the underlying feed format. This enables transparent support for all RSS versions including Atom. We also hide format specific implementation such as dates (RFC 822 in RSS 2.0 and 0.9x and ISO 8601 in RSS 1.0 and Atom) and other metadata.

The FeedParser distribution also includes:

  1. An implementation of RSS and Atom autodiscovery.
  2. Support for all content modules including xhtml:body, mod_content (RDF and inline), atom:content, and atom:summary
  3. Atom 1.0 link API as well as RSS 1.0 mod_link API
  4. An HTML link parser for finding all links in an HTML source file and expanding them to become full URLs instead of relative.

 

Supported Feed Formats

Jakarta FeedParser supports the following syndication formats:

RSS 1.0
RSS 0.9
RSS 0.91
RSS 0.92
RSS 2.0
Atom 0.3 (deprecated)
Atom 0.4 (deprecated)
Atom 0.5
OPML
FOAF
Changes.xml
XFN

In addition the following module supports is available:

Dublin Core (mod_dc)
mod_content
mod_aggregation
mod_dcterms
xhtml:body
Provided for XHTML RSS bodies
mod_taxonomy
Helps enables tags within RSS feeds
RSS 2.0 enclosures
wfw:commentRSS
WFW commentRSS support for linking to additional RSS feeds for comments

想知道其他做同类功能的兄弟,针对RSS的标准的差异,采用什么RSS解析组件解析RSS。希望大家拍砖!

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics