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

Serializing an array of data

Expand Messages
  • Andy Kelk
    Hi there, I have an array of data which I want to send in a SOAP request and expect it to come out something like this:
    Message 1 of 2 , Jan 29, 2003
    • 0 Attachment
      Hi there,

      I have an array of data which I want to send in a SOAP request and
      expect it to come out something like this:


      <skuElements>
      <product sku="Test">
      <categoryElements>
      <category xsi:type="xsd:string">1066</category>
      <category xsi:type="xsd:string">1020</category>
      </categoryElements>
      </product>
      </skuElements>



      Code snippet follows:

      --------------------------------- 8< -----------------------------------
      my $soap = SOAP::Lite
      -> uri('http://..../Test')

      -> proxy('http://.....');

      my @products;
      my @categories;
      my $data;
      $categories[0] = \SOAP::Data->name(category => '1066');
      $categories[1] = \SOAP::Data->name(category => '1020');
      $products[0] = SOAP::Data
      ->name(product => \SOAP::Data->value(SOAP::Data->name(categoryElements
      => @categories)))
      ->attr({sku => 'Test'});

      my $data = SOAP::Data
      ->name(SOAP::Data-> name(skuElements => \SOAP::Data->type(array =>
      @products)));


      print $soap
      -> TestFunction($data)

      -> result;

      --------------------------------- 8< -----------------------------------


      What I actually get from the debug is more like this:

      <skuElements>
      <product sku="Test">
      <categoryElements>
      <category xsi:type="xsd:string">1066</category>
      </categoryElements>
      <categoryElements>
      <category xsi:type="xsd:string">1020</category>
      </categoryElements>
      </product>
      </skuElements>

      Does anyone know why this might happen? I tried experimenting with
      different combinations of backslashes preceding the various SOAP::Data
      calls as mentioned in the HOWTO:
      http://soapenv.org/article.pl?sid=02/02/11/1740229&mode=thread

      I'm sure it's something really obvious I've missed.

      Thanks

      Andy

      --
      Andy Kelk
      Head of Integration, Venda
      andy@...
    • Andy Kelk
      Hi, Have managed to solve my own problem after a good night s sleep and a bit more trying. Adjusted Code snippet follows: my $soap = SOAP::Lite -
      Message 2 of 2 , Jan 30, 2003
      • 0 Attachment
        Hi,

        Have managed to solve my own problem after a good night's sleep and a
        bit more trying.


        Adjusted Code snippet follows:

        my $soap = SOAP::Lite
        -> uri('http://..../Test')
        -> proxy('http://.....');

        my @products;
        my @categories;
        my $data;

        $categories[0] = SOAP::Data->name(category => '1066');
        $categories[1] = SOAP::Data->name(category => '1020');

        $products[0] = SOAP::Data
        ->name(product => SOAP::Data
        ->name("categoryElements")
        ->value(\SOAP::Data->value(@categories));
        ->attr({sku => 'Test'});

        my $data = SOAP::Data
        ->name(SOAP::Data->name(skuElements => \SOAP::Data->type(array =>
        @products)));

        print $soap
        -> TestFunction($data)
        -> result;


        --
        Andy Kelk
        Head of Integration, Venda
        andy@...
      Your message has been successfully submitted and would be delivered to recipients shortly.