ROME 0.8 解析异常

发布于 2024-12-19 19:02:19 字数 904 浏览 5 评论 0原文

我正在尝试使用 ROME v0.8 (j2sdk1.4.2_07) 解析 RSS 提要,但无论我使用哪个提要,它总是显示相同的错误。

com.sun.synmination.io.ParsingFeedException:无效的 XML:错误 第 14 行:元素类型“meta”必须由匹配项终止 结束标记“”。

import java.net.URL;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

public class RssTest {

    public static void main(String[] args) {

    try {

            System.out.println("starting...");
            URL feedUrl = new URL("http://www.abc.net.au/news/feed/51120/rss.xml");
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = input.build(new XmlReader(feedUrl));

            System.out.println("Feed Title: " + feed.getTitle());

        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
        }
    }       
}

I am trying to parse RSS feeds using ROME v0.8 (j2sdk1.4.2_07) but no matter which feed I use it always says the same error.

com.sun.syndication.io.ParsingFeedException: Invalid XML: Error on
line 14: The element type "meta" must be terminated by the matching
end-tag "".

import java.net.URL;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

public class RssTest {

    public static void main(String[] args) {

    try {

            System.out.println("starting...");
            URL feedUrl = new URL("http://www.abc.net.au/news/feed/51120/rss.xml");
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = input.build(new XmlReader(feedUrl));

            System.out.println("Feed Title: " + feed.getTitle());

        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
        }
    }       
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏林苍穹下 2024-12-26 19:02:19

您的示例中的 URL 看起来像格式良好的 XML,并且不包含任何 meta 标记,因此它应该可以被 rome 解析。未终止的 meta 标记听起来像是返回 HTML 页面而不是实际的 feed。您是否可能在需要某些特殊登录的代理服务器后面?

The URL from your example looks like well-formed XML and does not contain any meta tag, so it should be parseable by rome. An unterminated meta tag makes it sound like something is returning a HTML page instead of the actual feed. Are your perhaps behind a proxy server that requires some special login?

一刻暧昧 2024-12-26 19:02:19

使用 InputSource 而不是 XmlReader

HttpURLConnection connection = (HttpURLConnection)url.openConnection();
InputStream is = connection.getInputStream();
InputSource source = new InputSource(is);
SyndFeedInput input = new SyndFeedInput();
feed = input.build(source);

Use InputSource instead of XmlReader:

HttpURLConnection connection = (HttpURLConnection)url.openConnection();
InputStream is = connection.getInputStream();
InputSource source = new InputSource(is);
SyndFeedInput input = new SyndFeedInput();
feed = input.build(source);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文