androidparsingxml-parsingtagsksoap2

How to store and parse soap object response


I am using soap to get response from server. I am trying to receive some bank information.from the response dump, I am getting the perfect response.But I don't know how to store and parse this object.

public void getbankinformation(String username,String password) 
    {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        //Property which holds input parameters
        PropertyInfo name = new PropertyInfo();
        name.setName("userName");
        name.setValue(username);
        name.setType(String.class);
        request.addProperty(name);
        PropertyInfo pass = new PropertyInfo();
        pass.setName("password");
        pass.setValue(password);
        pass.setType(String.class);
        request.addProperty(pass);


        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        try{
        HttpTransportSE httpTransport=new HttpTransportSE(URL);
        httpTransport.debug=true;
        httpTransport.call(NAMESPACE+METHOD_NAME, envelope);
        Log.d(TA,"HTTP Request: \n"+ httpTransport.requestDump);
        Log.d(TAE,"HTTP Response: \n"+ httpTransport.responseDump); 

        SoapObject result=(SoapObject)envelope.bodyIn;
        String[] testValues=new String[result.getPropertyCount()];
        for(int i=0;i<result.getPropertyCount();i++)
        {
            testValues[i]=result.getProperty(i).toString();

        }

        }
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();

        }
    }

Here is my response showing in logcat:

<?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>
    <GetBankInformationResponse xmlns="http://QuickManageITCL.org/">
      <GetBankInformationResult>
        <BankObject>
          <RID>string</RID>
          <ID>string</ID>
          <ShortName>string</ShortName>
          <Name>string</Name>
          <Address>string</Address>
          <BankTypeID>string</BankTypeID>
          <Note>string</Note>
          <CreatorUserID>string</CreatorUserID>
          <OranizationLogo>base64Binary</OranizationLogo>
        </BankObject>
        <BankObject>
          <RID>string</RID>
          <ID>string</ID>
          <ShortName>string</ShortName>
          <Name>string</Name>
          <Address>string</Address>
          <BankTypeID>string</BankTypeID>
          <Note>string</Note>
          <CreatorUserID>string</CreatorUserID>
          <OranizationLogo>base64Binary</OranizationLogo>
        </BankObject>
      </GetBankInformationResult>
    </GetBankInformationResponse>
  </soap:Body>
</soap:Envelope>

this is the soap response format I'm getting:

anyType{
BankObject=
  anyType{
    ID=001; 
    ShortName=ABBL; 
    Name=Arab Bangladesh Bank Limited; 
    Address=Dhaka; 
    BankTypeID=033; 
    Note=anyType{}; 
        }; 
BankObject=
  anyType{
    ID=032; 
    ShortName=BCBL; 
    Name=Bangladesh Commerce Bank Ltd.; 
    Address=anyType{}; 
    BankTypeID=033; 
    Note=anyType{}; 
    }; 
BankObject=
  anyType{
    ID=033; 
    ShortName=BPO; 
    Name=Bangladesh Post Office; 
    Address=anyType{}; 
    BankTypeID=031; 
    Note=anyType{}; 
    }; 
BankObject=
  anyType{
    ID=027; 
    ShortName=BAL; 
    Name=Bank Asia Limited; 
    Address=anyType{}; 
    BankTypeID=033; 
    Note=anyType{}; 
    }; 
BankObject=anyType{ID=002; ShortName=Basic; Name=Basic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=003; ShortName=BRAC; Name=BRAC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=004; ShortName=CBL; Name=City Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=035; ShortName=CBC; Name=Commercial Bank of Ceylon; Address=anyType{}; BankTypeID=032; Note=anyType{}; }; BankObject=anyType{ID=023; ShortName=DBL; Name=Dhaka Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=005; ShortName=DBBL; Name=Dutch-Bangla Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=006; ShortName=EBL; Name=Eastern Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=034; ShortName=EXBL; Name=Exim Bank; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=038; ShortName=FSIBL; Name=First Security islami Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=007; ShortName=ICB; Name=ICB; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=008; ShortName=IFIC; Name=IFIC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=025; ShortName=IBBL; Name=Islami Bank Bangladesh LTD.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=030; ShortName=ITCL; Name=ITCL; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=031; ShortName=anyType{}; Name=ITCL; Address=Tejgaon; BankTypeID=031; Note=anyType{}; }; BankObject=anyType{ID=009; ShortName=Jamuna; Name=Jamuna; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=010; ShortName=Janata; Name=Janata; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=021; ShortName=MBL; Name=Mercantile Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=011; ShortName=MTBL; Name=Mutual Trust Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=012; ShortName=NBL; Name=National Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=013; ShortName=NCC; Name=NCC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=014; ShortName=One Bank; Name=One Bank Ltd; Address=033; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=037; ShortName=Prime; Name=Prime Bank  Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=015; ShortName=Pubali; Name=Pubali Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=017; ShortName=SJBL; Name=Shahjalal Islami Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=026; ShortName=SIBL; Name=Social Islamic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=018; ShortName=Sonali; Name=Sonali Bank Limited; Address=anyType{}; BankTypeID=036; Note=anyType{}; }; BankObject=anyType{ID=036; ShortName=SEBL; Name=Southeast Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=022; ShortName=SBL; Name=Standard Bank Limited; Address=Dhaka; BankTypeID=033; Note=asdf; }; BankObject=anyType{ID=016; ShortName=SCB; Name=Standard Chartered Bank ; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=019; ShortName=TBL; Name=Trust Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=024; ShortName=UCBL; Name=United Commercial Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=020; ShortName=UBL; Name=Uttara Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; }

I want to parse this bank id,shortname,name,address,bank type id,note etc and store it to database.How'll I get my desired parsed value. I need a simple method.


Solution

  • The simplest - Name field from every bank:

    SoapObject res=(SoapObject)envelope.bodyIn;
    SoapObject t=(SoapObject)res.getProperty("GetBankInformationResult");
    for(int i=0; i<t.getPropertyCount(); i++){
        SoapObject bank=(SoapObject)t.getProperty(i);
        String name = bank.getProperty("Name").toString();
    }