//Initialize soap request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Use this to add parameters
request.addProperty("agentcode",agentCode);
request.addProperty("pincode",agentCodePin);
request.addProperty("appversion",appversion);
request.addProperty("deviceid",deviceid);
request.addProperty("latitude",latitude);
request.addProperty("longitude",longitude);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the web service
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader( result.toString()));
org.w3c.dom.Document doc = builder.parse(is);
doc.getDocumentElement().normalize();
//Get Node List
NodeList nlist = doc.getElementsByTagName("paypoint");
//Get node
Node nNode = (Node) nlist.item(0);
if (nNode.getType(0) == Node.ELEMENT)
{
//get element
Element elt = (Element) nNode;
// Get token
this.token = elt.getElementsByTagName("token").item(0).getTextContent();
// Get flag
this.flag = elt.getElementsByTagName("statusCode").item(0).getTextContent();
// Get agent name
this.agentName = elt.getElementsByTagName("fullname").item(0).getTextContent();
}
}
} catch (Exception e)
{
throw e;
}
return this.flag;
我在这一行遇到问题:is.setCharacterStream(new StringReader(result.toString()));
错误是:PI 不能以 xml 开头(部分:java.io.stringReader@40579f48 中的未知 xml@1:30)
我的 XML 文件如下所示:
<string xmlns="http://tempuri.org/">
<?xml version="1.0" encoding="utf-16"?><paypoint> <token>PkSMTTulAndNmM9R4Vmi+QRWtChW/Xs61sPERoTpB5eEgRfrQKUi6r2rqLQNusvJpVJ1oZBc8Z0=</token> <statusCode>1</statusCode><statusText>VALID USER</statusText><fullname>Dao Lacina</fullname><walletbalance>2000.00</walletbalance></paypoint>
任何帮助