我正在尝试使用 Rome 并且只是为了测试,我正在尝试获取一个简单的 RSS 提要并不断收到“无效 XML”错误。我实施了此解决方案中给出的解决方案,但它对我不起作用。我究竟做错了什么?
代码:
private void fetchRSSDetails() {
HttpClientFeedFetcher feedFetcher = new HttpClientFeedFetcher();
try {
SyndFeed feed = feedFetcher.retrieveFeed(new URL("http://feeds.bbci.co.uk/news/world/rss.xml"));
System.out.println(feed.getLink());
} catch (IllegalArgumentException | IOException | FeedException | FetcherException e) {
e.printStackTrace();
}
}
我得到的例外是:
com.rometools.rome.io.ParsingFeedException: Invalid XML
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:241)
at com.rometools.rome.io.SyndFeedInput.build(SyndFeedInput.java:154)
at com.rometools.fetcher.impl.HttpClientFeedFetcher.retrieveFeed(HttpClientFeedFetcher.java:354)
at com.rometools.fetcher.impl.HttpClientFeedFetcher.getFeed(HttpClientFeedFetcher.java:261)
at com.rometools.fetcher.impl.HttpClientFeedFetcher.retrieveFeed(HttpClientFeedFetcher.java:246)
at com.rometools.fetcher.impl.HttpClientFeedFetcher.retrieveFeed(HttpClientFeedFetcher.java:157)
at com.my.feed.subscriptions.SearchTask.fetchRSSDetails(SearchTask.java:168)
at com.my.feed.subscriptions.SearchTask.doInBackground(SearchTask.java:93)
at com.my.feed.subscriptions.SearchTask.doInBackground(SearchTask.java:54)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: org.jdom2.JDOMException: http://apache.org/xml/features/disallow-doctype-decl feature not recognized for SAX driver org.apache.harmony.xml.ExpatReader
at org.jdom2.input.SAXBuilder.internalSetFeature(SAXBuilder.java:1025)
at org.jdom2.input.SAXBuilder.configureParser(SAXBuilder.java:976)
at org.jdom2.input.SAXBuilder.buildEngine(SAXBuilder.java:856)
at org.jdom2.input.SAXBuilder.getEngine(SAXBuilder.java:904)
at org.jdom2.input.SAXBuilder.build(SAXBuilder.java:1196)
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:234)
... 15 more
下面是我如何将罗马添加到我的 Android 项目中。
compile ('com.rometools:rome:1.5.1'){
exclude module: 'slf4j-api'
}
compile ('com.rometools:rome-fetcher:1.5.1'){
exclude module: 'slf4j-api'
}
我一定错过了一些简单的东西......如果有人能指出我对罗马的任何好的文档可能会有所帮助。此外,如果你想推荐一些更容易使用的东西,我没有设置罗马和任何其他 RSS 解析库可以做的事情。我只需要解析 RSS 提要。