Leo*_*ied 7 android invalid-characters xml-parsing
我正在编写一个消耗一些XHTML的小屏幕抓取应用程序 - 不用说XHTML无效:&符号不会被转义为&.
我正在使用Android XmlPullParser,它会在错误编码的值上显示以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我考虑过以下解决方案:
InputStream另一个替换为带有实体引用的&符号哪些可能更成功?
我坚持了大约一个小时,然后才发现在我的情况下,XML PULL PARSER无法解决"&",所以我找到了解决方案.所以这里有一段完全修复它的代码片段.
void ParsingActivity(String r) {
try {
parserCreator = XmlPullParserFactory.newInstance();
parser = parserCreator.newPullParser();
// Here we give our file object in the form of a stream to the
// parser.
parser.setInput(new StringReader(r.replaceAll("&", "&")));
// as a SAX parser this will raise events/callback as and when it
// comes to a element.
int parserEvent = parser.getEventType();
// we go thru a loop of all elements in the xml till we have
// reached END of document.
while (parserEvent != XmlPullParser.END_DOCUMENT) {
switch (parserEvent) {
// if u have reached start of a tag
case XmlPullParser.START_TAG:
// get the name of the tag
String tag = parser.getName();
Run Code Online (Sandbox Code Playgroud)
几乎我正在做什么我只是替换了&,&因为我正在处理解析URL.希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
6250 次 |
| 最近记录: |