精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程

RSS 开发教程

来源:不详 时间:07-12-10 点击: 点击这里收藏本文
例 3 (RSS 2.0):

<rss:feed
url="http://static.userland.com/gems/backend/rssTwoExample2.xml"
feedId="example3"/>
<b>Image: </b><rss:channelImage feedId="example3"/><br>
<b>Title: </b><rss:channelTitle feedId="example3"/><br>
<b>Link: </b><rss:channelLink feedId="example3" asLink="true"/><br>
<b>Description: </b><rss:channelDescription feedId="example3"/><br>
<b>Copyright: </b><rss:channelCopyright feedId="example3"/><br>
<b>Docs: </b><rss:channelDocs feedId="example3"/><br>
<b>Generator: </b><rss:channelGenerator feedId="example3"/><br>
<b>Language: </b><rss:channelLanguage feedId="example3"/><br>
<b>Last Build Date: </b><rss:channelLastBuildDate
X-Virus: 1
feedId="example3"/><br>
<b>Managing Editor: </b><rss:channelManagingEditor
feedId="example3"/><br>
<b>Pub Date: </b><rss:channelPubDate feedId="example3"/><br>
X-Virus: 1
<b>Skip Days: </b><rss:channelSkipDays feedId="example3"/><br>
<b>Skip Hours: </b><rss:channelSkipHours feedId="example3"/><br>
<b>TTL: </b><rss:channelTTL feedId="example3"/><br>
<ul>
<rss:forEachItem feedId="example3" startIndex="2" endIndex="4">
<li><rss:itemDescription feedId="example3"/><br><br>
</rss:forEachItem>
</ul>

如何使用 RssParser?

从某种程度上看,语法分析器是该项目的副产品。尽管语法分析器是用标签库来开发的,但是它完全是自包含的,它可以在 Java 应用程序中使用。然而,要做到这一点,显然您至少需要了解如何编写基本的 Java 代码。(如果您了解如何用 Java 语言编写 Hello World,就没什么问题了。)

首先下载并解压包。一旦将 rssutils.jar 添加至您的类路径,就请使用 RssParserFactory 创建 RssParser 接口的实例:
RssParser parser = RssParserFactory.createDefault();
Rss rss = parser.parse(new
URL("http://mydomain.com/document.rss"));

语法分析器生成的 RSS 对象是位于提供的 URL 中的 RSS 文档的 Java 对象表示。使用 RSS 对象提供的方法以获得其它 RSS 对象的句柄,如 Channels 和 Items。RssParser 也能够分析 File 对象和 InputStream 对象。

结束语

RSS 提供了一种简单的方法来添加和维护您的 Web 站点上来自所有 Web 的新闻及其它内容。即使 RSS 是简单的 XML 格式,在 Web 上的其他任何地方从 XML 文档中分析并提取数据都可能有点棘手——或者至少单调乏味——如果您不得不一遍又一遍地去做的话。RSS Utilities Package 利用 Custom Tag 和 XML Parsing 技术使 "Real Simple Syndication" 格式真正做到文如其名。

9 7 3 1 2 4 8 :

用户评论

广而告之