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

       针对目前市场流行的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>

除了这些必须的元素外,RSS1.0还定义了三个附加元素:image、items和textinput,其中,image和textinput是可选的。另一方面,RSS2.0提供了16个附加元素,其中也包括image、items和textinput,此外还有language、copyright、managingEditor、pubDate和category。RSS1.0允许通过定义在单独的XML名字空间中的可扩展元素来创建这种类型的元数据。

这两种格式在结构上的主要区别必须要看其item、image和textinput节点的表示形式。RSS1.0中,channel元素包含对item、image和textinput节点的引用,这些节点存在于channel节点本身之外。这样在channel和所引用的节点之间建立了一种RDF关联。如Figure1所示,channel元素与一个image元素以及两个item元素关联。RSS2.0中,item元素只是在channel元素中连续排放(如Figure2所示)。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引擎已经支持当前的摘要格式。Figure3是一个Atom0.3提要例子,它与前述Figure1及Figure2RSS提要等同。注意Atom提要用名字空间限定的,但它不使用RDF。这使得Atom和RSS1.0及RSS2.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.0RSS 0.9RSS 0.91RSS 0.92RSS 2.0 Atom 0.3 (deprecated)Atom 0.4 (deprecated)Atom 0.5 OPMLFOAFChanges.xmlXFN

In addition the following module supports is available:

Dublin Core (mod_dc)mod_contentmod_aggregationmod_dctermsxhtml:bodyProvided for XHTML RSS bodiesmod_taxonomyHelps 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。希望大家拍砖!

相关推荐