Loading ...
Sorry, an error occurred while loading the content.

Decoding arrays of structures containing arrays

Expand Messages
  • Jenni Bennett
    I have written a SOAP::Lite Client to query a SOAP server using complex data types. I am having problems decoding the response. The response that is returned
    Message 1 of 3 , Feb 17, 2004
    • 0 Attachment
      I have written a SOAP::Lite Client to query a SOAP server using complex
      data types. I am having problems decoding the response. The response
      that is returned is similar to the following:

      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
      <fooResponse xmlns="http://foo.bar/foible/">
      <fooResult>
      <fooOut>
      <RecordId>27745</RecordId>
      <TransactionStatus>
      <StatusCode>Failure</StatusCode>
      <Messages>
      <Message>
      <Description>BirthDate can not be in the future</Description>
      <Severity>Error</Severity>
      </Message>
      </Messages>
      </TransactionStatus>
      </fooOut>
      <fooOut>
      <RecordId>31572</RecordId>
      <TransactionStatus>
      <StatusCode>Success</StatusCode>
      <Messages />
      </TransactionStatus>
      </fooOut>
      <ResponseControlTable>
      <RequestId>1</RequestId>
      <RequestStatus>
      <StatusCode>Success</StatusCode>
      <Messages>
      <Message>
      <Description>2 total transactions in request</Description>
      <Severity>Information</Severity>
      </Message>
      <Message>
      <Description>1 transactions completed successfully</Description>
      <Severity>Information</Severity>
      </Message>
      <Message>
      <Description>0 transactions completed with warnings</Description>
      <Severity>Information</Severity>
      </Message>
      <Message>
      <Description>1 transactions completed in error</Description>
      <Severity>Information</Severity>
      </Message>
      </Messages>
      </RequestStatus>
      </ResponseControlTable>
      </fooResult>
      </fooResponse>
      </soap:Body>
      </soap:Envelope>

      I am decoding with the following:

      my $i = 0;
      foreach my $elem ( $som->dataof('//fooResponse/fooResult/*') )
      {
      $i++;
      my $value = $elem->value();
      if ( $elem->name() eq "fooOut" )
      {
      print "RecordId: " . $value->{'RecordId'} . "\n";
      my $transStatus = $value->{'TransactionStatus'};
      print "StatusCode: " . $transStatus->{'StatusCode'} . "\n";

      foreach my $m ( $som->dataof('//fooResponse/fooResult/[$i]/TransactionStatus/Messages/*'))
      {
      print "Code: " . $m->{'Code'} . "\n";
      }
      }
      elsif ( $elem->name() eq "ResponseControlTable" )
      {
      print "RequestId: " . $value->{'RequestId'} . "\n";
      my $reqStatus = $value->{'RequestStatus'};
      print " StatusCode: " . $reqStatus->{'StatusCode'} . "\n";

      foreach my $m ( $som->valueof('//fooResponse/fooResult/[$i]/RequestStatus/Messages/Message') )
      {
      print "Code: " . $m->{'Code'} . "\n";
      }
      }
      }

      I am having problems accessing the "Message" elements returned in both the
      "fooOut" and "ResponseControlTable" elements. The two attempts
      above do not return any results. I have seen examples of accessing
      arrays of arrays but not arrays of structures containing arrays.

      Can someone suggest how I might be able to access this data?

      Jenni.
      --
      Jenni Bennett (jenni@...) /\
      IT Strategies and Developments (Emerging Technologies) _/./
      The University of Melbourne ,-' `-:..-'/
      : o ) _ (
      +61-3-8344-7497 "`-....,--; `-.\
      `'
    • Byrne Reese
      Could it be as simple as: -- CUT HERE -- foreach my $m ( $som- dataof( //Messages )) { print $m- {description}; } -- CUT HERE -- It is a valid XPath statement
      Message 2 of 3 , Feb 24, 2004
      • 0 Attachment
        Could it be as simple as:

        -- CUT HERE --
        foreach my $m ( $som->dataof('//Messages')) {
        print $m->{description};
        }
        -- CUT HERE --

        It is a valid XPath statement afterall... but you may want to access each
        segment of message elements independently from one another...

        >
        >
        >
        >
        > I have written a SOAP::Lite Client to query a SOAP server using complex
        > data types. I am having problems decoding the response. The response
        > that is returned is similar to the following:
        >
        >>?xml version="1.0" encoding="utf-8"?soap:Envelope
        >> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        >> xmlns:xsd="http://www.w3.org/2001/XMLSchema"soap:BodyfooResponse
        >> xmlns="http://foo.bar/foible/"fooResultfooOutRecordId/RecordIdTransactionStatusStatusCode/StatusCodeMessagesMessageDescription/DescriptionSeverity/Severity/Message/Messages/TransactionStatus/fooOutfooOutRecordId/RecordIdTransactionStatusStatusCode/StatusCodeMessages
        >> //TransactionStatus/fooOutResponseControlTableRequestId/RequestIdRequestStatusStatusCode/StatusCodeMessagesMessageDescription/DescriptionSeverity/Severity/MessageMessageDescription/DescriptionSeverity/Severity/MessageMessageDescription/DescriptionSeverity/Severity/MessageMessageDescription/DescriptionSeverity/Severity/Message/Messages/RequestStatus/ResponseControlTable/fooResult/fooResponse/soap:Body/soap:Envelope
        >
        >
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        > To visit your group on the web, go
        > to:http://groups.yahoo.com/group/soaplite/
        > To unsubscribe from this group, send an email
        > to:soaplite-unsubscribe@yahoogroups.com
        > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >


        ^byrne :/
      • Jenni Bennett
        Byrne, ... It was as simple as substituting double quotes for single... i.e. foreach my $m (
        Message 3 of 3 , Feb 24, 2004
        • 0 Attachment
          Byrne,

          On Tue, 24 Feb 2004, Byrne Reese wrote:

          > Could it be as simple as:
          >
          > -- CUT HERE --
          > foreach my $m ( $som->dataof('//Messages')) {
          > print $m->{description};
          > }
          > -- CUT HERE --
          >
          > It is a valid XPath statement afterall... but you may want to access each
          > segment of message elements independently from one another...

          It was as simple as substituting double quotes for single...

          i.e.
          foreach my $m (
          $som->dataof("//fooResponse/fooResult/[$i]/TransactionStatus/Messages/*"))
          {
          print "Code: " . $m->{'Code'} . "\n";
          }

          instead of:

          foreach my $m (
          $som->dataof('//fooResponse/fooResult/[$i]/TransactionStatus/Messages/*'))
          {
          print "Code: " . $m->{'Code'} . "\n";
          }

          Oops. :-/

          Thanks for the response.

          Jenni.
        Your message has been successfully submitted and would be delivered to recipients shortly.