Java-Rome:我试图解析RSS提要,但在某些频道上出错

Java-Rome:我试图解析RSS提要,但在某些频道上出错,java,xml,rss,rome,syndication-feed,Java,Xml,Rss,Rome,Syndication Feed,我正在尝试使用RSS并解析它。我找到了罗马,我正试图通过代码来处理它: private SyndFeed parseFeed(String url) throws IllegalArgumentException, FeedException, IOException { return new SyndFeedInput().build(new XmlReader(new URL(url))); } public Boolean processRSSConte

我正在尝试使用RSS并解析它。我找到了罗马,我正试图通过代码来处理它:

private SyndFeed parseFeed(String url) throws IllegalArgumentException, FeedException, IOException {
        return new SyndFeedInput().build(new XmlReader(new URL(url)));
    }


    public Boolean processRSSContent(String url) {
        try {
            SyndFeed theFeed = this.parseFeed(url);
            SyndEntry entry = theFeed.getEntries().get(0);
            ZonedDateTime entryUtcDate = ZonedDateTime.ofInstant(entry.getPublishedDate().toInstant(), ZoneOffset.UTC);
            String entryTitle = entry.getTitle();
            String entryText = entry.getDescription().getValue();
        }
        catch (ParsingFeedException e) {
            e.printStackTrace();
            return false;
        }
        catch (FeedException e) {
            e.printStackTrace();
            return false;
        }
        catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
在某些频道上,如everything,一切正常,但在其他一些频道上,如我收到错误:

Invalid XML: Error on line 5: The element type "meta" must be terminated by the matching end-tag "</meta>".
com.rometools.rome.io.ParsingFeedException: Invalid XML: Error on line 5: The element type "meta" must be terminated by the matching end-tag "</meta>". 
无效XML:第5行出错:元素类型“meta”必须由匹配的结束标记“”终止。
com.rometools.rome.io.ParsingFeedException:无效XML:第5行错误:元素类型“meta”必须由匹配的结束标记“”终止。
我看了一下这个链接背后的内容,XML真的很奇怪。但是它是一个很受欢迎的网站,我在其他一些网站上遇到了这个错误,所以我不认为XML存在问题。我做错了什么?如何阅读此RSS频道?

如果将url放到浏览器中,您会注意到它会重定向到。您的代码不处理重定向

我建议您使用from模块,它处理重定向并具有其他高级功能(缓存、条件GET、压缩):

EDIT:,但可以改用apachehttpclient,它更灵活

HttpClientFeedFetcher feedFetcher = new HttpClientFeedFetcher();
try {
    SyndFeed feed = feedFetcher.retrieveFeed(new URL("http://habrahabr.ru/rss/"));
    System.out.println(feed.getLink());
} catch (IllegalArgumentException | IOException | FeedException | FetcherException e) {
    e.printStackTrace();
}