我的Android应用程序正在调用.NET Web方法,并返回单个字符串。我使用的SAXParser解析一个字符串,如:在我的数据处理程序xml解析包含空格的单个字符串
<string xmlns="http://tempuri.org/">LOCAL NT AUTHORITY\NTLM Authentication Not in role Administrators</string>
和字符()函数:
public void characters(char ch[], int start, int length) {
String chars = new String(ch, start, length);
Log.v("characters", chars);
chars = chars.trim();
if (_inItem) {
_data = chars;
}
}
我的问题是,当我与网络服务器1测试它,它的作品确定但与Web服务器2它返回空字符串。
使用网络服务器1,我看到characters()函数只被调用一次,它返回整个字符串“LOCAL NT AUTHORITY \ NTLM身份验证不在角色管理员”。完善!
但与Web服务器2,charaters()函数被调用多次,它最终返回空字符串..?
04-20 10:09:43.161: VERBOSE/characters(405): LOCAL
04-20 10:09:43.161: VERBOSE/characters(405): NT AUTHORITY\NTLM Authentication
04-20 10:09:43.161: VERBOSE/characters(405): Not in role Administrators
04-20 10:09:43.250: VERBOSE/endElement(405): string=0
是否需要处理空间?这里发生了什么事?
我最终改变字符()函数:
public void characters(char ch[], int start, int length) {
String chars = new String(ch, start, length);
if (_inItem) {
_data += chars;
}
}
它们是否以不同的字符编码返回?在开始和结束标记中是否有打印行,以确保XML正确 – Blundell 2011-04-19 22:27:48
在Internet Explorer中,它们返回的是以<?xml version =“1.0”encoding =“utf-8”?> – bob 2011-04-19 22:35:36