我正在向 SOAP::Data 发送一个相当简单的 Perl 散列,但我没有得到我想要的带有散列数组的 XML。这是我要发送的内容:
'hash' => {
'Location' => [
{
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
},
{
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
},
],
}
这是我得到的:
<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>
但我想要的是这样的:
<hash>
<Location>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
</Location>
<Location>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
</Location>
</hash>
我错过了什么?我想如果我提供一些代码会有所帮助!:
my $hash = {};
my @Locations;
my @loc_codes = qw(0_4_10 0_51_117);
foreach my $l ( @loc_codes ) {
my @arr = split ('_', $l);
my $loc = {};
$loc->{key1} = $arr[0]; # country
$loc->{key2} = $arr[1]; # state
$loc->{key3} = $arr[2]; # city
push ( @Locations, $loc );
}
$hash->{Location} = \@Locations;
my $soap_elements = SOAP::Data->value(
SOAP::Data->name( 'some_method' => $hash )->prefix('p1')
)->prefix('p2');