How can convert local xml file to org.ksoap2.serialization.SoapObject? How can convert local xml file to org.ksoap2.serialization.SoapObject? android android

How can convert local xml file to org.ksoap2.serialization.SoapObject?


You can extend HttpTransportSE class and override method call like this:

public void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException{    if(localFileAvailable)    {        InputStream is = new FileInputStream(fileWithXml);        parseResponse(envelope, is);        is.close();    }    else    {        super.call(soapAction, envelope);    }}


The question was how to convert an xml file to a SoapObject. So how to get your input xml envelope into a ksoap2 call.

The way to do this is actually available within the HttpTransportSE class even though this was not its intended use!

There is a method "parseResponse" that takes in the envelope and an input stream(your xml file) and updates the envelope input header and body. But the clever thing is that you can copy these into the outHeader and outBody fields and then all the hard work of mapping fields goes away.

        @Overridepublic void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException {    if ( getFileInputStream() != null ){        parseResponse(envelope, getFileInputStream());        envelope.bodyOut = envelope.bodyIn;        envelope.headerOut = envelope.headerIn;        getFileInputStream().close();    }    super.call(soapAction,envelope);}