SOAP xml in return - Android

陌路散爱 提交于 2019-12-23 22:41:42

问题


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 {

    httpTransport.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.


回答1:


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




回答2:


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.




回答3:


Try it this WAy .

try {

    httpTransport.call(SOAP_ACTION, soapEnvelope);
    SoapObject result = (SoapObject) soapEnvelope.getResponse();


String element = ((SoapObject)result.getPropertySafely("schema")).getPropertySafely("element").toString(); 


来源:https://stackoverflow.com/questions/5421897/soap-xml-in-return-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!