Question

SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:getItemTypesResponse xmlns:ns2="http://Product/">
        <return>Laptop</return>
        <return>Netbook</return>
    </ns2:getItemTypesResponse>
</S:Body>

How do I parse this SOAP response in android?

Here's my code.

for(int i =0 ; i<count;i++){
            //SoapObject inner= (SoapObject)outer.getProperty(i);
            String s = null;
            s = outer.getProperty(i).toString();
            result.add(s);
        }
Was it helpful?

Solution

Create a class which implements the KvmSerializeable:

public class Import implements KvmSerializable {

String test;

public Import() {}

public Import (String test) {
    this.test = test;
}

public Object getProperty(int arg0) {

    switch (arg0) {

    case 0:
        return test;
    default:
        return test;
    }

}

public int getPropertyCount() {
    return 1;
}

public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {

    switch (arg0) {
    case 0:
        arg2.type = PropertyInfo.STRING_CLASS;
        arg2.name = "test";
        break;
    default:
        break;
    }

}

public void setProperty(int arg0, Object arg1) {

    switch (arg0) {
    case 0:
        test = (String) arg1;
        break;
    }

}

}

Just changes the variables so it fit's your need. And then:

        SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
                METHOD_NAME_NIST_IMPORT);

       Import import= new Import("Hello, World!");

        PropertyInfo pi = new PropertyInfo();
        pi.setName("req");
        pi.setValue(import);
        pi.setType(import.getClass());
        soapObject.addProperty(pi);


        SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapSerializationEnvelope.setOutputSoapObject(soapObject);

        soapSerializationEnvelope.addMapping(NAMESPACE, "Import", new Import().getClass());

To parse the response:

        SoapObject response = (SoapObject)soapSerializationEnvelope.getResponse();
        Import.test=  response.getProperty(0).toString();

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top