【发布时间】:2013-07-10 17:58:29
【问题描述】:
我正在尝试使用 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”字段或任何其他自定义字段的方法。
我从here 阅读了罗马的自定义模块,但我不知道如何使用它。我为webMaster字段创建了一个类似的SamplleModule、SampleModuleImpl和SampleModule Parser,但我不知道如何使用它!
这是我实现的类: 样品模块:
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);
}
SampleModuleImpl:
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。 我只是不知道如何在我的阅读器方法中使用它们。 有什么想法吗?
【问题讨论】:
-
您在 rome.properties 中的哪个位置添加了它?确保为要解析的 RSS 版本的 ModuleParser 元素设置它。
-
这不是问题。问题是我应该在我的代码中添加什么以获得“getWebMaster”方法?我的意思是我的第一个代码。