通过 ROME 解析 RSS 提要,获取 null 作为源
我正在使用 com.sun.syndicate api 来解析我最终需要在应用程序中使用的 RSS 提要。我面临的问题是,对于某些 RSS,例如,
http://rss.news.yahoo.com/rss/mostviewed
如果我们有带有某个值的标签,则以下代码将返回 null 作为源。
URL url = new URL("http://rss.news.yahoo.com/rss/mostviewed");
XmlReader reader = null;
try {
reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
System.out.println("Feed Title: "+ feed.getTitle());
for (Iterator<SyndEntry> i =feed.getEntries().iterator(); i.hasNext();) {
SyndEntry entry = i.next();
System.out.println("entry.getSource():"+entry.getSource());
}
有人知道我在这里可能会错过什么吗
I am using com.sun.syndication apis for parsing the RSS feeds which i need to eventually use in my application. The problem that i am facing is that for some of the RSS e.g. like
http://rss.news.yahoo.com/rss/mostviewed
Where we have tag with some value the following code returns null as source.
URL url = new URL("http://rss.news.yahoo.com/rss/mostviewed");
XmlReader reader = null;
try {
reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
System.out.println("Feed Title: "+ feed.getTitle());
for (Iterator<SyndEntry> i =feed.getEntries().iterator(); i.hasNext();) {
SyndEntry entry = i.next();
System.out.println("entry.getSource():"+entry.getSource());
}
Does someone has any idea on what i could just be missing here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎无法开箱即用,因为 RSS 2.0 的转换器忽略(可选)源元素。
您可以编写自己的转换器并根据项目的源属性自行设置源。我将值(您提要中的“AP”)放入此处的作者字段中:
幸运的是,通过更改
rome.properties
文件并设置MyConverterForRSS20<,可以轻松地将自定义转换器插入到 rome 中/code> 而不是
com.sun.synmination.feed.synd.impl.ConverterForRSS20
(文件的最后一行):This does not seem to work out of the box because the converter for RSS 2.0 is ignoring the (optional) source element.
You could write you own converter and set the source yourself from the item's source attribute. I put the value ("AP" from you feed) into the author field here:
Fortunately, the custom converter can be easily plugged into rome by changing the
rome.properties
file and settingMyConverterForRSS20
instead ofcom.sun.syndication.feed.synd.impl.ConverterForRSS20
(last line of file):