用了rome 0,8的jar包,代码大部分来自于rome-samples-0.7 。
对了,放个rome的链接Rome's Home,可以直接去下载。还有就是在用rome的时候,把信息输出到xml文件里
,部分出现乱码不知道是怎么回事,我读的feed文件是utf-8的,我也是通过utf8读的,但是还是有一部分乱码。今天找了一天也没有解决。。。
1 /*
2 * Created on 2006-7-11
3 *
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
6 */
7 package border;
8
9 import java.io.FileWriter;
10 import java.io.Writer;
11 import java.net.URL;
12 import java.util.List;
13
14 import com.sun.syndication.feed.synd.SyndContent;
15 import com.sun.syndication.feed.synd.SyndEntry;
16 import com.sun.syndication.feed.synd.SyndFeed;
17 import com.sun.syndication.fetcher.FeedFetcher;
18 import com.sun.syndication.fetcher.impl.FeedFetcherCache;
19 import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
20 import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
21 import com.sun.syndication.io.SyndFeedOutput;
22
23 /**
24 * @author Border
25 *
26 * TODO To change the template for this generated type comment go to Window -
27 * Preferences - Java - Code Style - Code Templates
28 */
29 public class RSSReader {
30 private static final String feedType = "rss_2.0";
31
32 public static void main(String[] args) throws Exception {
33
34 String filename = "E:\\ROME\\feed_fetcher2.xml";
35 try {
36 FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
37 FeedFetcher feedFetcher = new HttpURLFeedFetcher();
38 SyndFeed feed = feedFetcher.retrieveFeed(new URL(
39 "http://www.blogjava.net/border/Rss.aspx"));
40
41 feed.setFeedType(feedType);
42 feed.setTitle("Border's Blog");
43 feed.setDescription(" java Web3D FreeBsd ");
44 feed.setAuthor(" By:border ");
45 feed.setLink(" http://www.blogjava.net/border ");
46
47 List entryList = feed.getEntries();
48
49 for (int i = 0; i < entryList.size(); i++) {
50 SyndEntry entry = (SyndEntry) entryList.get(i);
51
52 entry.setPublishedDate(entry.getPublishedDate());
53 entry.setTitle(new String(entry.getTitle().getBytes("utf-8")));
54 entry.setLink(entry.getLink());
55
56 SyndContent content = entry.getDescription();
57 content.setValue(new String(content.getValue()
58 .getBytes("utf-8")));
59 }
60 SyndFeedOutput output = new SyndFeedOutput();
61 Writer writer = new FileWriter(filename);
62 output.output(feed, writer);
63
64 System.out.println("The feed has been written to the file ["
65 + filename + "]");
66 System.out.println(" ok !");
67
68 } catch (Exception e) {
69 System.out.println("ERROR: " + e.getMessage());
70 }
71 }
72 }
下面是生成的xml文件:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
3 <channel>
4 <title>Border's Blog</title>
5 <link>http://www.blogjava.net/border</link>
6 <description>java Web3D FreeBsd</description>
7 <language>zh-cn</language>
8 <pubDate>Thu, 06 Jul 2006 11:05:25 GMT</pubDate>
9 <dc:creator>By:border</dc:creator>
10 <dc:date>2006-07-06T11:05:25Z</dc:date>
11 <dc:language>zh-cn</dc:language>
12 <item>
13 <title>免费MySQL数据库申譿</title>
14 <link>http://www.blogjava.net/border/archive/2006/07/06/57015.html</link>
15 <description> <a href="http://www.db4free.net/"><img alt="" src="http://www.kuangfeng.cn/blog/wp-content/uploads/2006/03/db4free.jpg" align="left" border="0" /></a><br /><br /><br /><br /><a href="http://www.db4free.net/">Db4free</a>:专业提供免费数据库服务,支持 MySQL 5.0ﺿ5.1,支持使用Phpmyadmin进行管理,以后还将扩展支持PostgreSQL, Firebird 等数据库.<img src ="http://www.blogjava.net/border/aggbug/57015.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="/border/" target="_blank">Border</a> 2006-07-06 19:05 <a href="/border/archive/2006/07/06/57015.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div></description>
16 <pubDate>Thu, 06 Jul 2006 11:05:00 GMT</pubDate>
17 <guid isPermaLink="false">http://www.blogjava.net/border/archive/2006/07/06/57015.html</guid>
18 <dc:creator>Border</dc:creator>
19 <dc:date>2006-07-06T11:05:00Z</dc:date>
20 </item>
21 <item>
22 <title>刚刚大厦晃的利害,是不是有些地震叿 -- 北京</title>
23 <link>http://www.blogjava.net/border/archive/2006/07/04/56502.html</link>
24 <description> 刚刚大厦晃的利害,是不是有些地震叿 ,在17层感觉比较厉害,不知道在北京的其他同志有没有注意到<img src ="http://www.blogjava.net/border/aggbug/56502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="/border/" target="_blank">Border</a> 2006-07-04 12:20 <a href="/border/archive/2006/07/04/56502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div></description>
25 <pubDate>Tue, 04 Jul 2006 04:20:00 GMT</pubDate>
26 <guid isPermaLink="false">http://www.blogjava.net/border/archive/2006/07/04/56502.html</guid>
27 <dc:creator>Border</dc:creator>
28 <dc:date>2006-07-04T04:20:00Z</dc:date>
29 </item>
30 <item>
31 <title>通过js等比扩大图片的比伿</title>
32 <link>http://www.blogjava.net/border/archive/2006/07/03/56279.html</link>
33 <description>摘要: 在做web庿发的时㿙,显示图片是经常用到ῂ在默认的情况下图片是扩充,但是有的时㿙显示效果会不如人意。有时容器的大小是固定的,我们要把图片等比扩大<a href='http://www.blogjava.net/border/archive/2006/07/03/56279.html'>阅读全文</a>⾿<img src ="http://www.blogjava.net/border/aggbug/56279.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="/border/" target="_blank">Border</a> 2006-07-03 12:13 <a href="/border/archive/2006/07/03/56279.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div></description>
34 <pubDate>Mon, 03 Jul 2006 04:13:00 GMT</pubDate>
35 <guid isPermaLink="false">http://www.blogjava.net/border/archive/2006/07/03/56279.html</guid>
36 <dc:creator>Border</dc:creator>
37 <dc:date>2006-07-03T04:13:00Z</dc:date>
38 </item>
39 </channel>
40 </rss>
41
42
By:border