Reputation: 2037
I am using the KSoap2 for communicating with the server. The communication is fine and returns a set of values that i have mentioned below. I am not sure with the way i am handling the response. I wrote a separate java class that implements KvmSerializable for mapping the XML objects with the java objects. After a long research in the web, i found the use of the parser like SAX, DOM ..etc is more standard and flexible.
Is there any way i can bring the SAX for parsing the following response... if so,please provide some references..
This is the response that i got after i send a request to the server from my android client app. Please note, This response is not ended with .xml / returns as a .xml file.
This is the webclient response :
http://134.1.10.5/Maxima/MaximaSystem.asmx/ValidateLogin
<DataSet>
<xs:schema id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="UserIcode" type="xs:int" minOccurs="0"/>
<xs:element name="UserUserName" type="xs:string" minOccurs="0"/>
<xs:element name="UserPassword" type="xs:string" minOccurs="0"/>
<xs:element name="UserTypeICode" type="xs:int" minOccurs="0"/>
<xs:element name="ProfileTable" type="xs:string" minOccurs="0"/>
<xs:element name="UserTypeDesc" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram>
<NewDataSet>
<Table diffgr:id="Table1" msdata:rowOrder="0">
<Name>Frecan </Name>
<UserIcode>634</UserIcode>
<UserUserName>dairy</UserUserName>
<UserPassword>dairy123</UserPassword>
<UserTypeICode>632</UserTypeICode>
<ProfileTable/>
<UserTypeDesc>Dentist</UserTypeDesc>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
This is the response. No XML Tags ...anything...Please suggest the best way that i can parse it using the native parser of Android. If so, Please provide some references.
This is the sample of the response that i get, when i ping server through Android Client
anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=an
yType{complexType=anyType{sequence=anyType{element=anyType{....
// some values ........
};
element=anyType{};
element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{};
element=anyType{}; }; }; }; }; };unique=anyType{selector=anyType{};
field=anyType{};}; }; }; diffgram=anyType{}; }
Please let me know, is it possible to use native parsers in Android.
Thanks in Advance.
Upvotes: 3
Views: 3306
Reputation:
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null){
int count = result.getPropertyCount();
//TextView t = (TextView)this.findViewById(R.id.resultbox);
//t.setText("SOAP response:\n\n" + count);
SoapObject nameResult = (SoapObject) result.getProperty(0);
// TextView t = (TextView)this.findViewById(R.id.resultbox);
//t.setText("SOAP response:\n\n" + nameResult.toString());
SoapObject test = (SoapObject) nameResult.getProperty(1);
// TextView t = (TextView)this.findViewById(R.id.resultbox);
// t.setText("SOAP response:\n\n" + test.toString());
SoapObject dar = (SoapObject) test.getProperty(0);
//TextView t = (TextView)this.findViewById(R.id.resultbox);
//t.setText("SOAP response:\n\n" + dar.toString());
SoapObject suvas = (SoapObject) dar.getProperty(0);
int c = dar.getPropertyCount();
TextView t = (TextView)this.findViewById(R.id.resultbox);
t.setText("SOAP response:\n\n" + suvas.toString());
//t.setText("SOAP response:\n\n" + c);
//SoapObject nivas = (SoapObject) suvas.getProperty(NewsId);
//TextView t = (TextView)this.findViewById(R.id.resultbox);
// t.setText("SOAP response:\n\n" + nivas.toString());
}
First you have to get a soap response in soapObject and then after that count the total property.
After getting count, please check one by one in which property you have your data , you can also implement an inner loop.
Upvotes: 4