Skip navigation
Currently Being Moderated

Parsing SOAP response programmatically

Jun 15, 2012 7:54 AM

Good day,

 

I am connecting to a web service programmatically and with the following code I receive the result below:

 

var cURL = "http://localhost/soap/myservice.wsdl";

SOAP.wireDump = false;

var service = SOAP.connect(cURL);

var result = service.getReturnsIssuedPersonal("1","2");

 

Result:

<?xml version="1.0" ?>

- <RHISTORY>

<RETURN>INVALID</RETURN>

<RETURNTYPEREQ>1</RETURNTYPEREQ>

<PERIODREQ>2</PERIODREQ>

<TAXNAMEREQ>4</TAXNAMEREQ>

<SUBISSUE>5</SUBISSUE>

<REFNOREQ>3</REFNOREQ> </RHISTORY>
s

Is there a way that I can parse the result?
Kind regards,
Roy

I

 
Replies
  • Currently Being Moderated
    Jun 15, 2012 4:06 PM   in reply to roydene

    Hi Roy,

     

    You should be getting a JavaScript object back, add a console.println(result.toSource()); after the call, you should see something like;

     

    ({RHISTORY:{RETURN:"INVALID", RETURNTYPEREQ:1, PERIODREQ:2, TAXNAMEREQ:4, SUBISSUE:5, REFNOREQ:3}})

     

    So,

     

    console.println(result.RHISTORY.PERIODREQ);

     

    Will return 2.

     

    One trick if you have a repeating group returned is that the object will contain an array if there is more than 1 otherwise it will just be a nested object, so you might need some code like;

     

    if (response.Messages !== undefined)

    {

    if (response.Messages.length === undefined)

    {

        // only one back;

    }

    else

    {

        if (response.Messages.length > 0)

        {

          for (var i=0; i<response.Messages.length; i++)

          {

             // handle multiple response.Messages[i];

          }

        }

      }

    }

     

    Hope that helps

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 17, 2012 2:11 PM   in reply to roydene

    the format of the response is determined by the setting of

     

    cResponseStyle

     

    The default is  

    SOAPMessageStyle.JS

     

    but it looks like yours is set to

      

    SOAPMessageStyle.XML

     

     

    If you set it to Message, then you will get back JavaScript object literal which is a bit easier to deal with, e.g response.soapValue.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points