I'm working on an android app that utilizes my web services to fetch data and display it. My SOAP response is a bit complex and it looks like this.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetSessionDetailsResponse xmlns="https://viberservices.com/gcdev/">
<GetSessionDetailsResult>
<ModuleFlags>string</ModuleFlags>
<SessionID>string</SessionID>
<UserInfo>
<Fullname>string</Fullname>
<Language>long</Language>
</UserInfo>
<Locations>
<LocationDetails>
<LocationID>long</LocationID>
<LocationName>string</LocationName>
<PhotoURL>string</PhotoURL>
</LocationDetails>
<LocationDetails>
<LocationID>long</LocationID>
<LocationName>string</LocationName>
<PhotoURL>string</PhotoURL>
</LocationDetails>
</Locations>
</GetSessionDetailsResult>
</GetSessionDetailsResponse>
Now I want to get the Location ID and Location Name data from the Location part. And I'm using the following code.
SoapObject res=(SoapObject)envelope.bodyIn;
SoapObject t=(SoapObject)res.getProperty("Locations");
for(int i=0; i<t.getPropertyCount(); i++){
SoapObject locinfo=(SoapObject)t.getProperty(i);
String lid= locinfo.getProperty("LocationID").toString();
String lname= locinfo.getProperty("LocationName").toString();
}
//Code to display lid and lname
But I get a run time exception saying java.lang.RuntimeException: illegal property: Locations
I managed to overcome this by using the following code:
SoapObject res=(SoapObject)envelope.bodyIn;
SoapObject root=(SoapObject)((SoapObject)res.getProperty("GetSessionDetailsResult")).getProperty("Locations");
for(int i=0; i<root.getPropertyCount(); i++){
SoapObject t=(SoapObject)root.getProperty(i);
String lid= t.getProperty("LocationID").toString();
String lname= t.getProperty("LocationName").toString();
}