使用 Android 的 XmlPullParsers 解析无效的 & 符号 [英] Parsing invalid ampersands with Android's XmlPullParsers

查看:19
本文介绍了使用 Android 的 XmlPullParsers 解析无效的 & 符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个消耗一些 XHTML 的小屏幕抓取应用程序 - 不用说 XHTML 是无效的:与号不会转义为 &.

I am writing a little screen-scraping app that consumes some XHTML - it goes without saying that the XHTML is invalid: ampersands aren't escaped as &.

我正在使用 Android 的 XmlPullParser,它会在编码不正确的值时出现以下错误:

I am using Android's XmlPullParser and it spews out the following error upon the incorrectly encoded value:

org.xmlpull.v1.XmlPullParserException: unterminated entity ref 
(position:START_TAG <a href='/Fahrinfo/bin/query.bin/dox?ld=0.1&n=3&i=9c.0323581.1266265347&rt=0&vcra'>
@55:134 in java.io.InputStreamReader@43b1ef70) 

我该如何解决这个问题?我考虑过以下解决方案:

How do I get around this? I have thought about the following solutions:

  1. InputStream 包装在另一个中,用实体引用替换 & 符号
  2. 配置解析器,让它神奇地接受不正确的标记
  1. Wrapping the InputStream in another one that replaces the ampersands with entity refs
  2. Configuring the Parser so it magically accepts the incorrect markup

哪些可能更成功?

推荐答案

我会选择你的第一个选项,替换 & 符号似乎比另一个更合适.第二个选项似乎更像是一个hack,通过接受不正确的标记来让它工作.

I would go with your first option, replacing the ampersands seems more of a fit solution than the other. The second option seems more of a hack to get it to work by accepting incorrect markup.

这篇关于使用 Android 的 XmlPullParsers 解析无效的 & 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆