ROME を使用して、次のような RSS フィードを解析しようとしています。
url = new URL("http://www.rssboard.org/files/sample-rss-2.xml");
XmlReader reader = new XmlReader(url);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(reader);
System.out.println(feed.getAuthor());
ただし、「WebMaster」フィールドまたはその他のカスタマイズされたフィールドを取得する方法が見つかりません。
ここからローマのカスタムモジュールについて読みましたが、使い方がわかりませんでした。同様SamplleModule
の 、SampleModuleImpl
、およびSampleModule
webMaster フィールドのパーサーを作成しましたが、使用方法がわかりません。
これは私が実装したクラスです: SamplleModule:
public interface SampleModule extends Module {
public static final String URI =
"http://www.rssboard.org/files/sample-rss-2.xml";
public String getWebMaster();
public void setWebMaster(String webMaster);
}
サンプルモジュールの実装:
public class SampleModuleImpl extends ModuleImpl implements SampleModule {
private static final long serialVersionUID = 1L;
private String _webMaster;
protected SampleModuleImpl() {
super(SampleModule.class, SampleModule.URI);
}
@Override
public void copyFrom(Object obj) {
SampleModule sm = (SampleModule) obj;
setWebMaster(sm.getWebMaster());
}
@Override
public Class getInterface() {
return SampleModule.class;
}
@Override
public String getWebMaster() {
return _webMaster;
}
@Override
public void setWebMaster(String webMaster) {
_webMaster = webMaster;
}
}
および SampleModuleParser:
public class SampleModuleParser implements ModuleParser {
private static final Namespace SAMPLE_NS = Namespace.getNamespace("sample",
SampleModule.URI);
@Override
public String getNamespaceUri() {
return SampleModule.URI;
}
@Override
public Module parse(Element dcRoot) {
boolean foundSomething = false;
SampleModule fm = new SampleModuleImpl();
Element e = dcRoot.getChild("webMaster");
if (e != null) {
foundSomething = true;
fm.setWebMaster(e.getText());
}
return (foundSomething) ? fm : null;
}
}
これらのモジュールも rome.properties に追加しました。リーダーメソッドでそれらを使用する方法がわかりません。アイデアはありますか?