Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 31
Registered: ‎05-18-2014
My Device: z10
My Carrier: du
Accepted Solution

soap response parsing

Hi all,

 

i need to parse this below response .. but dont have idea

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
     <EmpltableWSServiceFindResponse xmlns="http://tempuri.org">
        <EmpltableWS xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/EmpltableWS">
           <DocPurpose>Original</DocPurpose>
           <SenderId>ceu</SenderId>
           <EmplTable class="entity">
              <_DocumentHash>30a13deb4619490c0fd70a5e56e70ad1</_DocumentHash>
              <ActivityEndTime>00:00:00</ActivityEndTime>
              <ActivityStartTime>00:00:00</ActivityStartTime>
              <ConfigurationCode>Admin</ConfigurationCode>
              <Department>Contoso Enterprise</Department>
              <Dimension>
                 <element>060</element>
                 <element>0201</element>
                 <element>Site1</element>
                 <element>1000</element>
                 <element>1000</element>
              </Dimension>
              <Email>TacMe@TacMe.com</Email>
              <eMailSaveCopy>No</eMailSaveCopy>
              <EmplGender>Male</EmplGender>
              <EmplId>1000</EmplId>
              <EmplName>Charlie Carson</EmplName>
              <EmplStatus>Active</EmplStatus>
              <Extension>04</Extension>
              <InclPrivateAppointments>No</InclPrivateAppointments>
              <InclPrivateTasks>No</InclPrivateTasks>
              <InclRecurringAppointments>No</InclRecurringAppointments>
              <IsManager>false</IsManager>
              <JoinDate>2013-01-01</JoinDate>
              <MobilePhone>0559999999</MobilePhone>
              <OnLeave>No</OnLeave>
              <OvertimeEnabled>No</OvertimeEnabled>
              <PartyId>590</PartyId>
              <PaymentMethod>Bank</PaymentMethod>
              <Phone>04999999</Phone>
              <Position>MGT. President BDM</Position>
              <RecId>5637144576</RecId>
              <RecVersion>1955879158</RecVersion>
              <ReportsTo>Julia Funderburk</ReportsTo>
              <ShiftEnabled>No</ShiftEnabled>
              <status>Employed</status>
              <TimeSheetEntryRequired>No</TimeSheetEntryRequired>
              <Title>President-BDM</Title>
              <ValidateEmplCategory>Yes</ValidateEmplCategory>
              <ValidateProjEmpl>Yes</ValidateProjEmpl>
           </EmplTable>
        </EmpltableWS>
     </EmpltableWSServiceFindResponse>
  </s:Body>
</s:Envelope>
 

 

On service response i am doing this following

 

void webservice:Smiley SurprisednServiceResponse() {

  

 qDebug() << "Responce Data main= >" << response.returnValue().toString();   // this value is empty

 

parseEmployeProfile(response.returnValue());

 

}

 

voidPMOwebservice:Smiley TonguearseEmployeProfile(constQtSoapType &data) {

 

        qDebug() << "Responce udatat after sending to parse = >" << data["DocPurpose"].toString(); // this value i am getting

        QString mData = data.toString();

 

        JsonDataAccess jda;

        QVariant qtData = jda.loadFromBuffer(mData);

        const QVariantMap mapRoot = qtData.value<QVariantMap>();

       const QVariantMap map = mapRoot.value("EmplTable", "").toMap();

        QString DocPurpose = map.value("DocPurpose", "").toString();   // this value is also empty

        

}

 

Dont have idea like how to parse this complex response....

 

waiting for your excelent reply...

 

 

Thanks in advnace..

Developer
Posts: 16,851
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: soap response parsing

SOAP is not JSON, so JsonDataAccess won't help you.

 

As it looks like you use QtSoap i can give you some help with that.

 

To see the response i use:

qDebug() << "soap response: " << resp.toXmlString(0);

 To parse it, just as an example (you will have to adjust it to your code)

QtSoapStruct &soapStruct = (QtSoapStruct &) resp.method();
int version = soapStruct["Version"].toInt();
QtSoapArray &attributes = (QtSoapArray &) soapStruct["Attributes"];
for (int i = 0; i < attributes.count(); ++i) {
    QtSoapStruct item = (QtSoapStruct&) attributes[i];
    QString attributeName = item["Attributename"].toString().toLower();
    QString objectName = item["Objectname"].toString();
    QString objectValue = item["Value"].toString();

 

On another project i use KDSoap, but it needs a (rather expensive) commercial license if your own project is also commercial.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 31
Registered: ‎05-18-2014
My Device: z10
My Carrier: du

Re: soap response parsing

Hi,

 

Thanks for the reply....

 

could please show me an example on how to use this 

 

QtSoapStruct &soapStruct = (QtSoapStruct &) resp.method();
int version = soapStruct["Version"].toInt();
QtSoapArray &attributes = (QtSoapArray &) soapStruct["Attributes"];
for (int i = 0; i < attributes.count(); ++i) {
    QtSoapStruct item = (QtSoapStruct&) attributes[i];
    QString attributeName = item["Attributename"].toString().toLower();
    QString objectName = item["Objectname"].toString();
    QString objectValue = item["Value"].toString();

 

I am new to blackberry development.....

 

Example means.. use the attributes and object name from the soap response i posted previously..

 

Thanks in advance....

Developer
Posts: 16,851
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: soap response parsing


nuelbruno wrote:

Example means.. use the attributes and object name from the soap response i posted previously..


No, that is not what example means.

It should not be too difficult to exchange attribute names, and it would be important that you understand what the code actually does.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 31
Registered: ‎05-18-2014
My Device: z10
My Carrier: du

Re: soap response parsing

Hi , I am using this code.. but the application is crashing if i use this QtSoapStruct &soapStruct = (QtSoapStruct &) response.method(); QtSoapArray &attributes = (QtSoapArray &) soapStruct["EmpltableWS"]; for (int i = 0; i < attributes.count(); ++i) { QtSoapStruct item = (QtSoapStruct&) attributes[i]; } and if i use this below code , app is not crashing... QtSoapStruct &soapStruct = (QtSoapStruct &) response.method(); QtSoapArray &attributes = (QtSoapArray &) soapStruct["EmpltableWS"]; for (int i = 0; i < attributes.count(); ++i) { } not sure how to use the parsing.... little help will be grateful...
Highlighted
Developer
Posts: 16,851
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: soap response parsing

please use the code tag to format code, it is not readable like this.
you can use the debugger to check where exactly the crash happens, maybe it helps.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter