- 4
- 0
- 约4.41千字
- 约 9页
- 2017-02-14 发布于重庆
- 举报
用JSP实现基于Web的RSS阅读器
用JSP实现基于Web的RSS阅读器
一: 介绍
?? 根据维基百科(/wiki/RSS)的定义,“RSS是一种用于共享新闻和其他Web内容的数据交换规范 ”,它是一系列的规范的组合,采用XML格式。目前国内RSS应用最多的是在新闻网站和博客网站上。
?? 许多网站可以用阅读器来个性化自己的网页,比如显示最新的新浪新闻,显示自己好朋友最新的博客文章,显示最新的论坛内容。除此之外,利用阅读器还可以实现其它用途,比如:
获得天气预报
接收邮件,比如就提供
获取最新股票行情
获取音乐,电台节目和视频剪辑等等
?
二:介绍
?? 这篇文章采用Rome这个开源工具来实现RSS阅读器。Rome支持的格式很多,有RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0 等等,几乎囊括了目前所有的RSS 和atom版本。最新的Rome版本可以从/bin/view/Javawsxml/Rome上得到。
?? 实现RSS阅读器,主要采用Rome的解析功能,就是从XML文件中读出相应的内容。我用一些简单代码来说明如何使用Rome中的类和方法。
URL feedUrl = new URL(/news/marquee/ddt.xml);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl)); 表一得到
?? “/news/marquee/ddt.xml“是新浪新闻的一个地址。通过三行代码,就可以得到一个对应这个地址的对象。这个对象包含我们所需要的所有内容。如果用,会得到表二中的结果。从中可以清楚地看到 类的结构。
SyndFeedImpl.contributors=null
新闻中心新闻要闻
SyndFeedImpl.categories[0].name=
SyndFeedImpl.categories[0].taxonomyUri=null
SyndFeedImpl.link=/iframe/o/allnews/input/index.htm
SyndFeedImpl.publishedDate=Thu Jun 22 13:20:01 CST 2006
SyndFeedImpl.entries[0].updatedDate=null
SyndFeedImpl.entries[0].contributors=null
SyndFeedImpl.entries[0].title=扎瓦赫里在录像带中呼吁阿富汗人抵抗外国侵略
SyndFeedImpl.entries[0].categories[0].name=
SyndFeedImpl.entries[0].categories[0].taxonomyUri=null
SyndFeedImpl.entries[0].link=/w/2006-06-22/11569270955s.shtml
SyndFeedImpl.entries[0].publishedDate=Thu Jun 22 11:56:00 CST 2006
SyndFeedImpl.entries[0].authors=null
SyndFeedImpl.entries[0].modules[0].descriptions=[]
SyndFeedImpl.entries[0].modules[0].creators[0]=WWW.SINA.COM.CN
SyndFeedImpl.entries[0].modules[0].contributors=[]
SyndFeedImpl.author=null
SyndFeedImpl.copyright=Copyright 1996 - 2005 SINA Inc. All Rights Reserved 表二: SyndFeed数据结构
从上述输出结果可以看出,每个新闻条目是由代表的。下列代码从中得到
List list = feed.getEntries();
for (int i=0; i list.size(); i++) {
SyndEntry entry = (SyndEntry)list.get(i);
} 表三:从中得到
如果程序位于防火墙后面,就需要在程序中加上一些设置。例如采用下面的:
Properties systemSettings = System.getProperties();
systemSettings.put(xyHost, )
原创力文档

文档评论(0)