通过rome读取feed,发现中文出现部分乱码。。

    用了rome 0,8的jar包,代码大部分来自于rome-samples-0.7 。
对了,放个rome的链接Rome's Home,可以直接去下载。还有就是在用rome的时候,把信息输出到xml文件里

<wbr>,部分出现乱码不知道是怎么回事<wbr>,我读的feed文件是utf-8的,我也是通过utf8读的<wbr>,但是还是有一部分乱码。今天找了一天也没有解决。。。

 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 >   &lt; a href="http://www.db4free.net/" &gt;&lt; img alt="" src="http://www.kuangfeng.cn/blog/wp-content/uploads/2006/03/db4free.jpg" align="left" border="0" / &gt;&lt; /a &gt;&lt; br / &gt;&lt; br / &gt;&lt; br / &gt;&lt; br / &gt;&lt; a href="http://www.db4free.net/" &gt; Db4free &lt; /a &gt; :专业提供免费数据库服务,支持 MySQL 5.0ﺿ5.1,支持使用Phpmyadmin进行管理,以后还将扩展支持PostgreSQL, Firebird 等数据库. &lt; img src ="http://www.blogjava.net/border/aggbug/57015.html" width = "1" height = "1" / &gt;&lt; br &gt;&lt; br &gt;&lt; div align=right &gt;&lt; a style="text-decoration:none;" href="/border/" target="_blank" &gt; Border &lt; /a &gt;  2006-07-06 19:05  &lt; a href="/border/archive/2006/07/06/57015.html#Feedback" target="_blank" style="text-decoration:none;" &gt; 发表评论 &lt; /a &gt;&lt; /div &gt; </ 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层感觉比较厉害,不知道在北京的其他同志有没有注意到὿ &lt; img src ="http://www.blogjava.net/border/aggbug/56502.html" width = "1" height = "1" / &gt;&lt; br &gt;&lt; br &gt;&lt; div align=right &gt;&lt; a style="text-decoration:none;" href="/border/" target="_blank" &gt; Border &lt; /a &gt;  2006-07-04 12:20  &lt; a href="/border/archive/2006/07/04/56502.html#Feedback" target="_blank" style="text-decoration:none;" &gt; 发表评论 &lt; /a &gt;&lt; /div &gt; </ 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庿发的时㿙,显示图片是经常用到ῂ在默认的情况下图片是扩充,但是有的时㿙显示效果会不如人意。有时容器的大小是固定的,我们要把图片等比扩大὿ &lt; a href='http://www.blogjava.net/border/archive/2006/07/03/56279.html' &gt; 阅读全文 &lt; /a &gt; ⾿ &lt; img src ="http://www.blogjava.net/border/aggbug/56279.html" width = "1" height = "1" / &gt;&lt; br &gt;&lt; br &gt;&lt; div align=right &gt;&lt; a style="text-decoration:none;" href="/border/" target="_blank" &gt; Border &lt; /a &gt;  2006-07-03 12:13  &lt; a href="/border/archive/2006/07/03/56279.html#Feedback" target="_blank" style="text-decoration:none;" &gt; 发表评论 &lt; /a &gt;&lt; /div &gt; </ 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
</wbr></wbr></wbr>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值