perl - Arrays of hashes sent to SOAP::Data -


i'm sending simple perl hash soap::data, i'm not getting xml want array of hashes. here's i'm sending it:

'hash' => {      'location' => [          {            'key1' => 'value1',            'key2' => 'value2',            'key3' => 'value3',          },          {            'key1' => 'value1',            'key2' => 'value2',            'key3' => 'value3',          },       ], } 

here's get:

<hash>   <location>       <c-gensym9>         <key1>value1</key1>         <key2>value2</key2>         <key3>value3</key3>       </c-gensym9>       <c-gensym10>         <key1>value1</key1>         <key2>value2</key2>         <key3>value3</key3>       </c-gensym10>   </location> </hash> 

but want this:

<hash>     <location>       <key1>value1</key1>       <key2>value2</key2>       <key3>value3</key3>     </location>     <location>       <key1>value1</key1>       <key2>value2</key2>       <key3>value3</key3>     </location> </hash> 

what missing? suppose it'd if gave code!:

my $hash = {}; @locations; @loc_codes = qw(0_4_10 0_51_117);  foreach $l ( @loc_codes ) {   @arr = split ('_', $l);   $loc = {};   $loc->{key1} = $arr[0];  # country   $loc->{key2} = $arr[1];  # state   $loc->{key3} = $arr[2];  # city    push ( @locations, $loc ); }  $hash->{location} = \@locations;    $soap_elements = soap::data->value(   soap::data->name( 'some_method' => $hash )->prefix('p1') )->prefix('p2'); 

you need strict, first of all

use strict; use soap::lite +trace => 'all';  @loc_codes = qw(0_4_10 0_51_117); @locations;  foreach $l ( @loc_codes ) {   @arr = split ('_', $l);   $loc =   soap::data     ->name("location" => \soap::data->value(       soap::data->name('key1', $arr[0]),       soap::data->name('key2', $arr[1]),       soap::data->name('key3', $arr[2])));    push ( @locations, $loc ); }  $soap_elements; $soap_elements = soap::data->value(       soap::data->name( hash => \@locations ));  $serializer = soap::serializer->new(); $serializer->readable('true'); $xml = $serializer->serialize($soap_elements); print $xml; 

generates

<hash   soapenc:arraytype="xsd:anytype[2]"   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"   xmlns:xsd="http://www.w3.org/2001/xmlschema"   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"   xsi:type="soapenc:array">  <location>   <key1 xsi:type="xsd:int">0</key1>   <key2 xsi:type="xsd:int">4</key2>   <key3 xsi:type="xsd:int">10</key3>  </location>  <location>   <key1 xsi:type="xsd:int">0</key1>   <key2 xsi:type="xsd:int">51</key2>   <key3 xsi:type="xsd:int">117</key3>  </location> </hash> 

so think need build array elements first


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -