通过 Rome 解析 RSS 提要时,序言中不允许获取内容
使用 Rome API 解析 RSS 提要我收到此错误:
com.sun.syndication.io.ParsingFeedException: Invalid XML
at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:210)
代码如下:
public static void main(String[] args) {
URL url;
XmlReader reader = null;
SyndFeed feed;
try {
url = new URL("https://www.democracynow.org/podcast.xml");
reader = new XmlReader(url);
feed = new SyndFeedInput().build(reader);
for (Iterator<SyndEntry> i =feed.getEntries().iterator(); i.hasNext();) {
SyndEntry entry = i.next();
System.out.println(entry.getPublishedDate()+" Title "+entry.getTitle());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
我检查了一些链接,例如:
问题可能出在字符集上,但我无法找到实现此方法的方法。 任何帮助或指导将不胜感激。
感谢和问候,
Vaibhav Goswami
Using Rome API to parse the RSS feeds I am getting this error :
com.sun.syndication.io.ParsingFeedException: Invalid XML
at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:210)
The code is as below:
public static void main(String[] args) {
URL url;
XmlReader reader = null;
SyndFeed feed;
try {
url = new URL("https://www.democracynow.org/podcast.xml");
reader = new XmlReader(url);
feed = new SyndFeedInput().build(reader);
for (Iterator<SyndEntry> i =feed.getEntries().iterator(); i.hasNext();) {
SyndEntry entry = i.next();
System.out.println(entry.getPublishedDate()+" Title "+entry.getTitle());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
I checked for some of the links like :
Where the problem is presumably is of charsets but I could not figure a way to get this implemented.
Any help or guidance would be highly appreciative.
Thanks and Regards,
Vaibhav Goswami
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也在使用联合组织,并且可以获得发布日期和标题。
我的代码如下:
这有效,我使用 Bloomberg Url 只是因为它给了我一个 XML。
如果您有其他疑问,请告诉我:)
I am using Syndication as well and i am able to get published date and title.
My code is as follows:
This works , and i have used Bloomberg Url just cause it gives me a XML.
If your query was something else , do let me know :)
您可以使用 SyndFeed 和 SyndEntry 来解析 xml
另外您还需要检查 xml 是否有效
you can use SyndFeed and SyndEntry for parsing the xml
Also you need to check whether the xml is a valid one
这是由于字节顺序标记问题造成的。下面是一个 JUnit 测试用例,演示了问题和修复:
It's due to a Byte Order Mark problem. Here is a JUnit test case that demonstrates the problem and the fix: