1
我想使用羅馬,只是爲了測試,我試圖獲取一個簡單的RSS源,並不斷收到「無效的XML」錯誤。我執行this solution中給出的解決方案,但它不適合我。我究竟做錯了什麼?羅馬HttpClientFeedFetcher給出「無效的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'
}
我一定會缺少一些簡單的...如果任何人能指出我對任何有用的羅馬文檔有幫助。另外,如果你想推薦一些更容易使用的東西,我不會在羅馬和任何其他的Java解析庫中設置。我只需要解析RSS提要。