風(fēng)人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評(píng)論 - 56, 引用 - 0

          導(dǎo)航

          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(11)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          收藏夾

          友情鏈接

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          Rome使用入門

          Rome的兩種使用方法
          所需jar包的下載 here,在這里可以找到與rome相關(guān)的所有文件

          1、只使用rome
          ???
          package com.ivo.rss;

          import java.io.IOException;
          import java.net.URL;
          import java.util.Iterator;

          import com.sun.syndication.feed.synd.SyndEntry;
          import com.sun.syndication.feed.synd.SyndFeed;
          import com.sun.syndication.io.FeedException;
          import com.sun.syndication.io.SyndFeedInput;
          import com.sun.syndication.io.XmlReader;
          public class Feed {
          ??? public static void main(String[] args) throws Exception {

          ???????
          ??????? SyndFeedInput input = new SyndFeedInput();
          ??????? //System.out.println(warmedFeed);
          ??????? SyndFeed feed = input.build(new XmlReader(new URL("
          http://rss.news.yahoo.com/rss/topstories ")));

          ??????? // Iterate through feed items, adding a footer each item
          ??????? Iterator entryIter = feed.getEntries().iterator();
          ??????? while (entryIter.hasNext()) {
          ??????????? SyndEntry entry = (SyndEntry) entryIter.next();
          ??????????? System.out.println(entry.getPublishedDate());
          ??????????? System.out.println(entry.getTitle());
          ??????????? //System.out.println(entry.getDescription());
          ??????????? //System.out.println(entry.getAuthor());
          ??????????? System.out.println(entry.getLink());
          ???????????
          ??????? }
          ??? }

          }

          2、使用rome+rome fetcher

          package com.ivo.rss;

          import java.net.URL;
          import java.util.List;

          import com.sun.syndication.feed.synd.SyndContent;
          import com.sun.syndication.feed.synd.SyndEntry;
          import com.sun.syndication.feed.synd.SyndFeed;
          import com.sun.syndication.fetcher.FeedFetcher;
          import com.sun.syndication.fetcher.impl.FeedFetcherCache;
          import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
          import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;

          public class RssReader {

          ??? public static void main(String[] args) throws Exception {
          ??????? FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
          ??????? FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
          ??????? SyndFeed feed = feedFetcher.retrieveFeed(new URL(
          ??????????????? "
          http://feeds.feedburner.com/jscud "));
          ??????? List entryList = feed.getEntries();
          ??????? for (int i = 0; i < entryList.size(); i++) {
          ??????????? SyndEntry entry = (SyndEntry) entryList.get(i);
          ??????????? System.out.println("Published Date: "+entry.getPublishedDate());
          ??????????? System.out.println("Title: "+entry.getTitle());
          ??????????? System.out.println("Link: "+entry.getLink());
          ??????????? //System.out.println(entry.getDescription());
          ??????????? SyndContent sc = entry.getDescription();
          ??????????? System.out.println("Description: "+sc.getValue());
          ??????????? System.out.println("------------------------------");
          ??????? }
          ??? }
          }

          上面是使用了緩存的,也就是說更新才讀取,如果每次都讀取,則修改對(duì)應(yīng)行為:

          FeedFetcher feedFetcher = new HttpURLFeedFetcher();

          posted on 2006-07-07 14:20 風(fēng)人園 閱讀(1330) 評(píng)論(3)  編輯  收藏 所屬分類: Java

          評(píng)論

          # re: Rome使用入門  回復(fù)  更多評(píng)論   

          我在用的時(shí)候,中文有部分亂碼問題,不知道你是怎么解決的,
          如果可以的話,說說你的方法.

          2006-07-11 18:32 | Border

          # re: Rome使用入門  回復(fù)  更多評(píng)論   

          你指哪一部分?
          輸出的時(shí)候嗎?
          2006-07-17 15:55 | 風(fēng)人園

          # re: Rome使用入門  回復(fù)  更多評(píng)論   

          當(dāng)你把你讀到的feed輸出到xml文件的時(shí)候,在xml文件會(huì)出現(xiàn)亂碼,不知道怎么解決,謝謝你的回復(fù),我剛剛才看到。嘿嘿

          具體的情況可以看看: http://www.aygfsteel.com/border/archive/2006/07/12/57848.html
          2006-07-21 09:24 | BorderJ
          主站蜘蛛池模板: 迁西县| 华蓥市| 荔波县| 巢湖市| 张家港市| 浮山县| 庄浪县| 永清县| 登封市| 牟定县| 新和县| 伊通| 峨边| 永清县| 汉沽区| 灵寿县| 高台县| 会东县| 平顶山市| 余干县| 闸北区| 宁强县| 莱西市| 黄大仙区| 永靖县| 穆棱市| 丁青县| 封丘县| 饶阳县| 河南省| 玉门市| 辉南县| 马公市| 中宁县| 即墨市| 亳州市| 泸州市| 山阳县| 读书| 含山县| 惠水县|