Am very new to Android apps development. In my new Android app i want to show some data from webservice. This means i have a SOAP message
, i need to parse the data from SOAP response. In iPhone app i knew very well to parse SOAP message response but, in android i don't know how to do this? I searched lot in Google and get some ideas. But, am very confusing on this. Can anyone please suggest any easiest way to understand SOAP send request/receive response and parse(XML format
) the response in SAXParser
in Android
? I has installed ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar
in my project. Here i found some sample code, i post here,
import java.io.*;
import org.ksoap2.SoapEnvelope;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;
public class ParsingSteps
{
public static void main(String[] args)
{
try{
// String msg="<hello>World!</hello>";
String msg = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://
www.w3.org/2001/12/soap-envelope\" " + "xmlns:xsi=\"http://www.w3.org/
2001/XMLSchema-instance <http://www.w3.org/%0A2001/XMLSchema-instance>\""
+"xmlns:xsd=\"http://www.w3.org/2001/
XMLSchema\"& gt;" +
"<SOAP-ENV:Body>" +
"<result>" +
"<message xsi:type=\"xsd:string\">Hello World</message>" +
"</result>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
// byte[] in= msg.getBytes();
KXmlParser parser=new KXmlParser();
parser.setInput(new StringReader(msg));
SoapEnvelope soapenvelope= new SoapEnvelope
(SoapEnvelope.VER12);
//soapenvelope.parse(parser);
soapenvelope.parseBody(parser);
}
catch (IOException e) {
System.out.println("Error reading URI: " + e.getMessage ());
} catch (XmlPullParserException e) {
System.out.println("Error in parsing: " + e.getMessage ());
}
// String result=parser.getName();
//System.out.println(result);
}
}
Is this correct code. Please give any suggestion on my question. Please help me on this. Thanks in advance.