XML を返す SOAP POST を送信しています。新しいデバイス (Galaxy Nexus with Android 4.1) でテストしてきましたが、問題なく動作しています。ただし、古いデバイス (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≷
変わります<
。
なぜこれが問題なのですか?どうすれば修正できますか?