1

I have a problem with parsing complex response of KSoap2.

My response XML file is:

<Word>breadth</Word>
<Definitions>
  <Definition>
    <Word>breadth</Word>
    <Dictionary>
      <Id>gcide</Id>
      <Name>The Collaborative International Dictionary of English v.0.44</Name>
    </Dictionary>
    <WordDefinition>Breadth \Breadth\ (br[e^]dth)</WordDefinition>
  </Definition>
  <Definition>
    <Word>breadth</Word>
    <Dictionary>
      <Id>moby-thes</Id>
      <Name>Moby Thesaurus II by Grady Ward, 1.0</Name>
    </Dictionary>
    <WordDefinition>87 Moby Thesaurus words for "breadth": </WordDefinition>
  </Definition>
</Definitions>

My Class file is:

public class MainActivity extends Activity {

    private static final String SOAP_ACTION = "http://services.aonaware.com/webservices/Define"; 
    private static final String NAMESPACE = "http://services.aonaware.com/webservices/";
    private static final String METHOD_NAME = "Define";
    private static final String URL = "http://services.aonaware.com/DictService/DictService.asmx";
    int n=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

        PropertyInfo pi1=new PropertyInfo();
        pi1.setName("word");
        pi1.setValue("breadth");
        pi1.setType(String.class);
        request.addProperty(pi1);


        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport =new HttpTransportSE(URL);
        try{
            androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
            SoapObject resultAns = (SoapObject)soapEnvelope.getResponse();
            System.out.println("Full ans: "+resultAns);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

My output on LogCat is:

Here 1: anyType{Word=breadth; Definitions=anyType{Definition=anyType{Word=breadth; Dictionary=anyType{Id=gcide; Name=The Collaborative International Dictionary of English v.0.44; }; WordDefinition=Breadth \Breadth\ (br[e^]dth)
; }; Definition=anyType{Word=breadth; Dictionary=anyType{Id=moby-thes; Name=Moby Thesaurus II by Grady Ward, 1.0; }; WordDefinition=87 Moby Thesaurus words for "breadth":
; }; }; }

I have been searching from 2 days.. still I am not able to parse it. and I am new to ksoap2.. so i dont know the proper way to parse complex objects. So can you tell me how did you get the values from it?

Edit:I don't have trouble with connection, All i want to know is to Get the data from Xml nodes, The problem is that this XML has node inside of another node. So i think actual effort starts from that soupEnvelope.getResopnse() line. Help Plz!

Palak Darji
  • 1,084
  • 18
  • 28

0 Answers0