Android RSS Xml 错误
我试图从 URL 解析 Xml 文件,该 xml 实际上是一个 RSS 提要。但是,当我调用
Document dom = builder.parse(podcastUrl.openConnection().getInputStream());
或
Document dom = builder.parse(new InputSource(podcastUrl.openStream()));
抛出此异常时:
unterminated entity ref (position:ENTITY_REF &T@7:14 in java.io.InputStreamReader@47b601c0)
播客的类型为 URL。
我做错了什么?
Im trying to parse a Xml file from a URL, the xml is actually a RSS feed. However when I call
Document dom = builder.parse(podcastUrl.openConnection().getInputStream());
or
Document dom = builder.parse(new InputSource(podcastUrl.openStream()));
I get this exception thrown :
unterminated entity ref (position:ENTITY_REF &T@7:14 in java.io.InputStreamReader@47b601c0)
podcast is of Type URL.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也遇到了类似的问题。经过查找原因,我发现如果 xml 格式不正确(意味着它包含
&
或其他未格式化的字符),则会抛出此错误。我必须解决这些问题才能使其正常工作。就我而言,
&
是要转换为&
,如此简单,但花了我一些时间来了解它。I was also having the similar problem. And after searching the reason, I found that if xml is not well formatted (means it contains
&
or other chars without being formatted) this error is thrown. I had to fix such issues to make it work.In my case
&
is to be converted to&
, so simple but consumed my some time to know it.异常消息听起来好像提要实际上不是格式良好的 XML。这很可能是由链接查询字符串中的未转义与号 (
&
) 引起的。该链接可能如下所示:XML 解析器会尝试将以
&T
开头的部分解释为字符实体,并抱怨它不是以分号终止的。在 XML 文档中,&
符号必须像这样进行转义:您作为评论发布的链接解析正常,因此这可能只是一个临时问题。
The exception message sounds like the feed is actually not well-formed XML. This is most likely caused by an unescaped ampersand (
&
) in the query string of a link. The link might have looked like this:An XML parser would try to interpret the part starting with
&T
as a character entity and complain that it is not terminated by a semicolon. In a XML document the&
sign has to be escaped like this:The link you posted as a comment parses OK, so it might have been just a temporary problem.
您可以使用 RSS 提要库来解析 RSS 提要 url。看看我在这里的答案我认为这对你有帮助 Android Xml Parsing空指针异常
You can use RSS FEED LIBRARY to parse the rss feed urls. Just look at my answer here I think this is helpful to you Android Xml Parsing Null Pointer exception
找到一个链接
http://devtuts.mobi/Android:RSS_Parser
解释了一种不同的方法。效果很好!
Found a link
http://devtuts.mobi/Android:RSS_Parser
Explains a different way of doing it. Works Great!!