RSS4jは、RSSの解析/生成に特化したXMLパーサーです。

配布元

http://www.churchillobjects.com/c/13005.html
このほかに、 Xercesが必要です。

RSS4jのデータ構造

RssDocument := RssChannel*
RssChannel := Channel属性 RssItem*
RssItem := Item属性 RssDublicCore

ソースコード

public final class RSSRSS4JReader {
 public static void main(String[] args) {
   final String xmlUrlString =
         "http://hondou.homedns.org/pukiwiki/pukiwiki.php?cmd=rss10";

   try {
     // URL接続を開く
     URL xmlUrl = new URL(xmlUrlString);
     HttpURLConnection httpConn = (HttpURLConnection) xmlUrl.openConnection();
     httpConn.setRequestMethod("GET");

     InputStream xmlInput = httpConn.getInputStream();
     
     // Rssの読み込み開始
     RssDocument doc = RssParser.parseRss(xmlInput);
     System.out.println("RSS file parsed.");

     // Rssの読み込み結果の表示
     Enumeration enum = doc.channels();
     while (enum.hasMoreElements()) {
       RssChannel channel = (RssChannel) enum.nextElement();
       System.out.println("Channel:Title:       " + channel.getChannelTitle());
       System.out.println(
         "       :Description: " + channel.getChannelDescription());
       System.out.println("       :Link:        " + channel.getChannelLink());

       Enumeration items = channel.items();

       while (items.hasMoreElements()) {
         RssChannelItem item = (RssChannelItem) items.nextElement();
         System.out.println("Item:Title:       " + item.getItemTitle());
         System.out.println("     Description: " + item.getItemDescription());
         System.out.println("     Link:        " + item.getItemLink());
         System.out.println("     Date:        " + item.getDublinCore().getDateAs8601());
       }
     }
   } catch (RssParseException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
}

読み込み結果

RSS4jでRSSを出力するには

// RSSドキュメントオブジェクトのインスタンス化
RSSDocument doc = new RSSDocument();
doc.setVersion(RSSDocument.VERSION_10);

//
// setterでデータをセット,
//

// OutputStreamに書き出す
RSSGenerator.generateRss( doc , OutputStream ); 

Java


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2006-02-18 (土) 13:44:24 (6635d)
Short-URL:
ISBN10
ISBN13
9784061426061