SOAP xml in return - Android
I'm using k2SOAP for Android when dealing with webservices.
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ProjectID", 1);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
try {
httpTra开发者_运维问答nsport.call(SOAP_ACTION, soapEnvelope);
SoapObject result = (SoapObject) soapEnvelope.getResponse();
String resultString = result.toString();
}
I know there is nothing wrong with the code since it works with the w3 web service. But w3c returns a string as an answer this web service returns an XML. The answer I get back looks like this when I show it in log:
anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=an yType{complexType=anyType{sequence=anyType{element=anyType{};
element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; };
unique=anyType{selector=anyType{}; field=anyType{}; }; }; }; diffgram=anyType{}; }
Which basically is a lot of noise and I'm not sure on how to get the information from this or how I should parse it or. My ultimate goal is to put the information I get in to a local database but since I don't know how to get the information from the String I don't know put the info in the database.
So what I want to do is to somehow parse the information and put it in a local database which I already built the classes for. How do I get the data from the SoapObject result? There is a slight possibility the web service info is empty, but my question is still the same.
Two Things you need to change
1)Add this "httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");"
line above "httpTransport.call(SOAP_ACTION, soapEnvelope);"
2) String resultString = result.toString();
Replace the above line with following one
String resultString=httpTransport.responseDump;
This will return response as xml formated String
The provided answer did not work for me rather lines bellow worked for me. Try the following lines, hope this will give you data with XML tags,
httpTransport.debug=true;
httpTransport.call(SOAP_ACTION, soapEnvelope);
String ss=httpTransport.responseDump;
Log.d("Result --- ", ss);
This will print the complete xml file which has been returned by the web service.
Try it this WAy .
try {
httpTransport.call(SOAP_ACTION, soapEnvelope);
SoapObject result = (SoapObject) soapEnvelope.getResponse();
String element = ((SoapObject)result.getPropertySafely("schema")).getPropertySafely("element").toString();
精彩评论