我正在发送返回一些 xml 的 SOAP POST。我一直在更新的设备(带有 Android 4.1 的 Galaxy Nexus)上进行测试,并且运行良好。但是,我只是尝试在旧设备(运行 Android 2.2 的 HTC Desire HD)上运行它,我得到了ParseException: At line 1, column 0: unclosed token
. 以下是相关代码:
String xml = null;
Document doc = null;
String SOAPRequest = "[SOAP REQUEST HERE]";
HttpPost httppost = new HttpPost("[WEBSITE HERE]");
InputStream soapResponse = null;
try {
StringEntity postEntity = new StringEntity(SOAPRequest, HTTP.UTF_8);
postEntity.setContentType("text/xml");
httppost.setHeader("Content-Type", "application/soap+xml;charset=UTF-8");
httppost.setEntity(postEntity);
HttpClient httpclient = new DefaultHttpClient();
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(httppost);
// Convert HttpResponse to InputStream
HttpEntity responseEntity = httpResponse.getEntity();
soapResponse = responseEntity.getContent();
//// printing response here gives me ...<Result><blahblahblah><Result>...
// Get the SearchResult xml
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
doc = db.parse(soapResponse);
} catch ...
NodeList soapNodeList = doc.getElementsByTagName("Result");
xml = soapNodeList.item(0).getFirstChild().getNodeValue();
//// printing xml here gives me "<"
return xml;
看一下httpResponse,我感兴趣的部分是这样的:<Result><blahblahblah></Result>
.
当我尝试使用 , 得到这个xml
时NodeList
,<blahblahblah≷
变成了字符<
。
为什么这是一个问题,我该如何解决?