(转自:http://www.jspcn.net/htmlnews/6006203177.html)
操作rss文件就是操作xml文件,要为网站动态生成rss订阅,就得学习怎么样操作xml文件,这里是个现成的rss文件生成库,可以拿来用用,长远之计还是必须学习一下xml文件的生成。
正文
×××××××××××××××××××××××××××××××××××××××××××××××××××××
实现RSS
作者:wanghui 文章来源:www.jspcn.net
访问次数: 次 加入时间:2005-07-05
RSS是一个标准的XML文件,Rss阅读器可以读取这个XML文件获得文章的信息,使用户可以通过Rss阅读器而非浏览器阅读Blog,我们只要动态生成这个XML文件便可以了。RSSLibJ是一个专门读取和生成RSS的小巧实用的Java库,大小仅25k,可以从http://sourceforge.net/projects/rsslibj/下载rsslibj-1_0RC2.jar和它需要的EXMLjar两个文件,然后复制到web/WEB-INF/lib/下。
使用RSSLibJ异常简单,我们先设置好HttpServletResponse的Header,然后通过RSSLibJ输出XML即可:
Channel channel = new Channel();
channel.setDescription(account.getDescription());
baseUrl = baseUrl.substring(0, n);
channel.setLink("http://server-name/home.c?accountId=" + accountId);
channel.setTitle(account.getTitle());
List articles = facade.getArticles(accountId, account.getMaxPerPage(), 1);
Iterator it = articles.iterator();
while(it.hasNext()) {
Article article = (Article)it.next();
channel.addItem("http://server-name/article.c?articleId=" + article.getArticleId(),
article.getSummary(), article.getTitle()
);
}
// 输出xml:
response.setContentType("text/xml");
PrintWriter pw = response.getWriter();
pw.print(channel.getFeed("rss"));
pw.close();
可以下载来看看它的rss文件生成是怎么样实现的。
我读的源码太少了。
×××××××××××××××××××××××××××××××××××××××××××××××××××××
Anonymous CVS Access
This project's SourceForge.net CVS repository can be checked out through anonymous (pserver) CVS with the following instruction set. The module you wish to check out must be specified as the modulename. When prompted for a password for anonymous, simply press the Enter key. To determine the names of the modules created by this project, you may examine their CVS repository via the provided web-based CVS repository viewer.
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/rsslibj login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/rsslibj co -P modulename
Information about accessing this CVS repository may be found in our document titled, "CVS (Version Control for Source Code)".