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

complex data structures

Expand Messages
  • Hostile
    Hi all I have been using SOAP::LIte for a while though always having both client and server using SOAP::LIte. I now find myself using SOAP to call 3rd party
    Message 1 of 1 , Oct 10, 2004
    • 0 Attachment
      Hi all

      I have been using SOAP::LIte for a while though always having both
      client and server using SOAP::LIte. I now find myself using SOAP to
      call 3rd party web services and the data structures are a nested mix
      of hashes and arrays etc.

      I am having problems with arrays. I cannot reproduce this using a
      SOAP::Lite server, it only happens when I am reading from an Apache
      Axis server which I have no control over. So I assume this is
      something to do with the underlying SOAP::Data objects.

      This is an example of what is occuring.

      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body'))."\n";
      --code


      --output
      $VAR1 = [
      {
      'key1' => {
      'key11' => {
      'key111' => 'a',
      'key112' => {
      'key1121' => 'b',
      'key1122' => 'c'
      }
      }
      }
      }
      ];
      --output


      This is not what I expected, I should get something like:

      --snip
      $VAR1 = [
      {
      'key1' => {
      'key11' => [
      {
      'key111' => 'a',
      'key112' => [
      {
      'key1121' => 'b',
      'key1122' => 'c'
      },
      {
      'key1123' => 'd',
      'key1124' => 'e'
      }
      ]
      },
      {
      'key113' => 'f',
      'key114' => [
      {
      'key1141' => 'g',
      'key1142' => 'h'
      },
      {
      'key1143' => 'i',
      'key1144' => 'j'
      }
      ]
      }
      ]
      }
      }
      ];
      --snip


      Ok, progressing further in depth:

      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body/key1'))."\n";
      --code


      --output
      $VAR1 = [
      {
      'key11' => {
      'key111' => 'a',
      'key112' => {
      'key1121' => 'b',
      'key1122' => 'c'
      }
      }
      }
      ];
      --output

      where as I would expect


      --snip
      $VAR1 = [
      {
      'key11' => [
      {
      'key111' => 'a',
      'key112' => [
      {
      'key1121' => 'b',
      'key1122' => 'c'
      },
      {
      'key1123' => 'd',
      'key1124' => 'e'
      }
      ]
      },
      {
      'key113' => 'f',
      'key114' => [
      {
      'key1141' => 'g',
      'key1142' => 'h'
      },
      {
      'key1143' => 'i',
      'key1144' => 'j'
      }
      ]
      }
      ]
      }
      ];
      --snip


      Ok, progressing further in depth:

      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body/key1/key11'))."\n";
      --code

      --output
      $VAR1 = [
      {
      'key111' => 'a',
      'key112' => {
      'key1121' => 'b',
      'key1122' => 'c'
      }
      },
      {
      'key113' => 'f',
      'key114' => {
      'key1141' => 'g',
      'key1142' => 'h'
      }
      }
      ];
      --output

      where as I would expect:

      --snip
      $VAR1 = [
      {
      'key111' => 'a',
      'key112' => [
      {
      'key1121' => 'b',
      'key1122' => 'c'
      },
      {
      'key1123' => 'd',
      'key1124' => 'e'
      }
      ]
      },
      {
      'key113' => 'f',
      'key114' => [
      {
      'key1141' => 'g',
      'key1142' => 'h'
      },
      {
      'key1143' => 'i',
      'key1144' => 'j'
      }
      ]
      }
      ];
      --snip

      Ok, so at this point, it is show more than one parameter, so here I
      was thinking, great, I can access everything ...


      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body/key1/key11/[1]'))."\n";
      --code

      --output
      $VAR1 = 'a';
      $VAR1 = 'f';
      --output

      Ok, this is definetely not what I expected. I thought it would give
      me the first parameter in the array, not the first value of each hash
      inside each parameter. Say something like:

      --snip
      $VAR1 = [
      {
      'key111' => 'a',
      'key112' => [
      {
      'key1121' => 'b',
      'key1122' => 'c'
      },
      {
      'key1123' => 'd',
      'key1124' => 'e'
      }
      ]
      }
      ];
      --snip

      More ...

      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body/key1/key11/[2]'))."\n";
      --code

      --output
      $VAR1 = {
      'key1121' => 'b',
      'key1122' => 'c'
      };
      $VAR2 = {
      'key1123' => 'd',
      'key1124' => 'e'
      };
      $VAR3 = {
      'key1141' => 'g',
      'key1142' => 'h'
      };
      $VAR4 = {
      'key1143' => 'i',
      'key1144' => 'j'
      };
      --output


      Ok ... now imagine when I want to access deeper past these arrays ..


      Lets make a slight change to the complete structure which is actually
      more like what I have:

      --snip
      $VAR1 = [
      {
      'key1' => {
      'key11' => [
      {
      'key111' => 'a',
      'key112' => [
      {
      'name' => 'b',
      'value' => 'c'
      },
      {
      'name' => 'd',
      'value' => 'e'
      }
      ]
      },
      {
      'key113' => 'f',
      'key114' => [
      {
      'name' => 'g',
      'value' => 'h'
      },
      {
      'name' => 'i',
      'value' => 'j'
      }
      ]
      }
      ]
      }
      }
      ];
      --snip


      --code
      my $som = $soap->getStuff;
      print Data::Dumper::Dumper($som->valueof('//Envelope/Body/key1/key11/[2]/value'))."\n";
      --code

      --output
      $VAR1 = 'c';
      $VAR2 = 'e';
      $VAR3 = 'h';
      $VAR4 = 'j';
      --output

      Ok, so I am guessing that I CAN access anything ... but its not as
      easy as it could be.

      What I really want, is a nice hash/array structure I can just travese.
      Then I can use on generic soap client and not one per service.

      Am I over looking anything?

      Change request, how about a method called nice_body which doesnt clip arrays? :)
      I tried to make my own using valueof and just recursing up in depth
      but I am struggling at arrays.

      Is there a better way?

      Cheers

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