Parsing soap without using ksoap in android
to access wsdl service from android i use the following
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(BASIC_URL);
try {
StringEntity se = new StringEntity(SoapRequest, HTTP.UTF_8);
se.setChunked(true);
se.setContentType("text/xml");
httpPost.addHeader("Accept-Encoding", "gzip,deflate");
httpPost.addHeader("SOAPAction", SoapAction);
httpPost.addHeader("Content-Type", "text/xml;charset=UTF-8");
httpPost.addHeader(header);
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity resEntity = httpResponse.getEntity();
// response = EntityUtils.toString(resEntity);
return httpResponse;
} catch (Exception e) {
}
where SoapRequest is a soap string, received a response from the server, but how to parse a soap response since I am not using HttpTransportSE and ksoap . i dont have a soap object as an answer.
- Is this the correct way to access the wsdl service from android?
- it is possible to convert soap object to xml or json and then parse it
sample response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org /soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetResponse xmlns="http://tempuri.org/">
<GetResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="First">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstElement" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<NewDataSet xmlns="">
<Exception diffgr:id="Exception1" msdata:rowOrder="0">
<ex_id>12</ex_id>
</Exception>
<Second diffgr:id="Second" msdata:rowOrder="0">
<SecondElement>66</SecondElement>
</Second>
</NewDataSet>
</GetResult>
</GetResponse>
+3
source to share
1 answer
We can parse Soap's response as parsing xml.Using xmlpull. We can extract the xml tags. Don't need them HttpTransportSE and ksoap
public void fetchXML(){
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myparser = xmlFactoryObject.newPullParser();
myparser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES
, false);
myparser.setInput(new StringReader("Soap response here"));
parseXML(myparser);
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
public void parseXML(XmlPullParser myParser) {
int event;
String text=null;
try {
event = myParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
String name=myParser.getName();
switch (event){
case XmlPullParser.START_TAG:
break;
case XmlPullParser.TEXT:
text = myParser.getText();
break;
case XmlPullParser.END_TAG:
if(name.equals("ex_id")){
Log.i("----", text);
}
break;
}
event = myParser.next();
}
} catch (Exception e) {
e.printStackTrace();
}
}
0
source to share