wildcatsの日記

赤羽在住でIT関係の会社の社長やってます。

Informa

仕事でRSSフィードをパースしなければならなかったのでRSSのParserを調べてみた。
http://java-source.net/open-source/rss-rdf-tools
ここ経由でInformaを触ってみた。
@ITRSSフィード(RSS 1.0)をinformaでパースしてタイトルだけ表示するサンプル
依存ライブラリ
informa.jar 0.6.5
jdom.jar
commons-logging.jar


package jp.mydns.wildcats.test.informa;

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

import de.nava.informa.core.ChannelIF;
import de.nava.informa.core.ItemIF;
import de.nava.informa.core.ParseException;
import de.nava.informa.impl.basic.ChannelBuilder;
import de.nava.informa.parsers.FeedParser;

public class Main {

public static void main(String[] args) {
URL url = null;
try {
url = new URL("http://www.atmarkit.co.jp/rss/rss2dc.xml");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
ChannelIF channel = null;
try {
channel = FeedParser.parse(new ChannelBuilder(), url);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ParseException e) {
throw new RuntimeException(e);
}
Collection col = channel.getItems();
for (Iterator it = col.iterator(); it.hasNext();) {
ItemIF item = (ItemIF) it.next();
System.out.println(item.getTitle());
}
}
}