Android SAX org.apache.harmony.xml.ExpatParser$ParseException格式不正确(无效标记)-西班牙语字符
我一直想弄明白为什么我的Android SAX解析器不喜欢©和ñ等字符 我可以有几个解析例程,它们要么解析获取我服务器上的xml文件的http调用的结果,要么解析生成xml的Web服务器的结果。对于xml文件来说,一切都很酷 但是,返回自制atom提要的Web服务器会导致我的应用程序出现异常: org.apache.harmony.xml.ExpatParser$ParseException:第73行第27列:格式不正确(无效令牌) 注意UTF_8这件事 我的xml文件如下所示,导致问题的字符串是año:Android SAX org.apache.harmony.xml.ExpatParser$ParseException格式不正确(无效标记)-西班牙语字符,android,xml,sax,Android,Xml,Sax,我一直想弄明白为什么我的Android SAX解析器不喜欢©和ñ等字符 我可以有几个解析例程,它们要么解析获取我服务器上的xml文件的http调用的结果,要么解析生成xml的Web服务器的结果。对于xml文件来说,一切都很酷 但是,返回自制atom提要的Web服务器会导致我的应用程序出现异常: org.apache.harmony.xml.ExpatParser$ParseException:第73行第27列:格式不正确(无效令牌) 注意UTF_8这件事 我的xml文件如下所示,导致问题的字符串
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>News</title>
<id>SUCCESS</id>
<generator>News</generator>
<updated>2013-12-04T04:40:59Z</updated>
<language xmlns="">SPANISH</language>
<entry>
<title>Disfrutando el año de Gracias con la familia</title>
<link rel="alternate" type="text/html" href="http:/www.the.com/zocalo/news/1/810b28c1-289b-41d7-b4bb-148b0f52a83a/news_sp.xml" />
<link rel="enclosure" type="image/jpg" href="http://www.the.com.net/zocalo/news/1/810b28c1-289b-41d7-b4bb-148b0f52a83a/img1.png" />
<link rel="enclosure" type="image/jpg" />
etc
</entry>
</feed>
新闻
成功
新闻
2013-12-04T04:40:59Z
西班牙文
这是一个家庭问题
等
你知道我应该检查什么吗?任何帮助都将不胜感激。谢谢 使用和#169代码>代替)
和Ñ代码>代替ñ
您的xml将是有效的。最终找到了一个解决方案,它是由saxParser编码“&”(特殊字符)的问题,因此我将“&”替换为&。现在它工作正常,代码如下所示:
response = response.replaceAll("&", "&"); // Your Server Response
InputSource inputSource = new InputSource();
inputSource.setEncoding("UTF-8");
Log.i("TAG", "Response>>>>" + response);
inputSource.setCharacterStream(new StringReader(response));
xr.parse(inputSource);
我在代码中也面临同样的问题,我尝试了以下解决方案。这对我有用
InputSource inputSource = new InputSource();<br/>
inputSource.setEncoding("ISO-8859-1");<br/>
inputSource.setCharacterStream(new StringReader(response));<br/>
xr.parse(inputSource);
InputSource InputSource=新的InputSource()
inputSource.setEncoding(“ISO-8859-1”)
setCharacterStream(新StringReader(响应))
xr.parse(inputSource);
您能解释一下响应是什么类型的变量吗?
InputSource inputSource = new InputSource();<br/>
inputSource.setEncoding("ISO-8859-1");<br/>
inputSource.setCharacterStream(new StringReader(response));<br/>
xr.parse(inputSource);