RSS4jは、RSSの解析/生成に特化したXMLパーサーです。
http://www.churchillobjects.com/c/13005.html
このほかに、
Xercesが必要です。
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(); } } }
// RSSドキュメントオブジェクトのインスタンス化 RSSDocument doc = new RSSDocument(); doc.setVersion(RSSDocument.VERSION_10); // // setterでデータをセット, // // OutputStreamに書き出す RSSGenerator.generateRss( doc , OutputStream );