博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java实现RSS
阅读量:4196 次
发布时间:2019-05-26

本文共 2886 字,大约阅读时间需要 9 分钟。

RSS是一个标准的XML文件,Rss阅读器可以读取这个XML文件获得文章的信息,使用户可以通过Rss阅读器
而非浏览器阅读Blog,我们只要动态生成这个XML文件便可以了。RSSLibJ是一个专门读取和生成RSS的小
巧实用的Java库,大小仅25k,可以从下载rsslibj-
1_0RC2.jar和它需要的EXMLjar两个文件,然后复制到web/WEB-INF/lib/下。
 
rsslibj-1_0RC2.jar下载地址:
 
EXML.jar下载地址:
 
下载下来之后把 扩张名.zip 改为 .jar 就行了。
import com.rsslibj.elements.Channel;public class Writer {    public static void main(String[] args)             throws InstantiationException, ClassNotFoundException,             IllegalAccessException {        Channel channel=new Channel();        channel.setDescription("This is my sample channel.");        channel.setLink("http://localhost/");        channel.setTitle("My Channel");        channel.setImage("http://localhost/",                 "The Channel Image",                 "http://localhost/foo.jpg");        channel.setTextInput("http://localhost/search",                 "Search The Channel Image",                 "The Channel Image",                 "s");        channel.addItem("http://localhost/item1",                "The First Item covers details on the first item>",                "The First Item")                .setDcContributor("Joseph B. Ottinger");        channel.addItem("http://localhost/item2",                "The Second Item covers details on the second item",                "The Second Item")                .setDcCreator("Jason Bell");        System.out.println("The feed in RDF: "+channel.getFeed("rss"));    }}
 
 
Channel channel = new Channel(); channel.setDescription(account.getDescription()); baseUrl=\'#\'"  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();
 
 
  importcom.rsslibj.elements.Channel;      publicclassWriter{
  publicstaticvoidmain(String[]args)   throwsInstantiationException,ClassNotFoundException,   IllegalAccessException{
  Channelchannel=newChannel();   channel.setDescription("Thisismysamplechannel.");   channel.setLink("/");   channel.setTitle("MyChannel");   channel.setImage("/",   "TheChannelImage",   "/foo.jpg");   channel.setTextInput("/search",   "SearchTheChannelImage",   "TheChannelImage",   "s");   channel.addItem("/item1",   "TheFirstItemcoversdetailsonthefirstitem>",   "TheFirstItem")   .setDcContributor("JosephB.Ottinger");   channel.addItem("/item2",   "TheSecondItemcoversdetailsontheseconditem",   "TheSecondItem")   .setDcCreator("JasonBell");   System.out.println("ThefeedinRDF:" channel.getFeed("rdf"));   }   }

本文出自 “” 博客

转载地址:http://skkli.baihongyu.com/

你可能感兴趣的文章
交大研究生,就一个字牛
查看>>
Android开发之ADB使用
查看>>
Android模拟器使用模拟SD卡
查看>>
Redis入门教程
查看>>
Google code上利用SVN托管代码
查看>>
技术的发展与互联网的发展
查看>>
工作流简介
查看>>
软件项目管理实践之日计划
查看>>
浅析大型网站的架构
查看>>
电脑故障排除经验
查看>>
数据库升级脚本制作
查看>>
HTTP response splitting 攻击
查看>>
Google十三年
查看>>
SSL原理
查看>>
预编译头sadafx.h原理
查看>>
DLL编写教程
查看>>
WebService WSDL详解(上)
查看>>
WebService WSDL详解(下)
查看>>
公司旅游--金华武义二日游
查看>>
虚拟机四种网络连接模式比较
查看>>