in reply to Re^4: XML::Simple for sequence in xsd
in thread XML::Simple for sequence in xsd

For a start, there's one simple change that needs to be made. Replace:
{ %NewOrder_data, }
with:
\%NewOrder_data,
Then, at least, $xmlDS will preserve the order that you assigned. (You can verify that with print Dumper($xmlDS), "\n";)

However, the order gets lost in the final step when $request_xml is assigned its value. I couldn't find an easy way to deal with that ... perhaps XML::Simple also needs to 'use Tie::IxHash;' for this approach to work.

Cheers,
Rob

Replies are listed 'Best First'.
Re^6: XML::Simple for sequence in xsd
by syphilis (Archbishop) on Aug 20, 2007 at 12:47 UTC
    I couldn't find an easy way to deal with that

    But moritz had found the solution to that in an earlier post in this thread (moritz++). It's just a matter of replacing:
    my $xs = new XML::Simple(keeproot => 1, SuppressEmpty => 1);
    with:
    my $xs = new XML::Simple(keeproot => 1, SuppressEmpty => 1, NoSort + => 1);
    Here's the (final) amended version of the script:
    use strict; use XML::Simple; use Data::Dumper; use Tie::IxHash; my $Request_data = {}; tie my %NewOrder_data , 'Tie::IxHash'; tie my %r, 'Tie::IxHash'; my $request_xml = \%r; %NewOrder_data = ( 'IndustryType' => ['EC'], 'CurrencyCode' => ['840'], 'CurrencyExponent1' => ['1'], 'CurrencyExponent2' => ['2'], ); my @keys = keys %NewOrder_data; print "\n@keys\n"; my $xmlDS = { Request => [ { NewOrder => [ \%NewOrder_data, ], } ], }; $request_xml = eval { my $xs = new XML::Simple(keeproot => 1, SuppressEmpty => 1, NoSort + => 1); $xs->XMLout($xmlDS); }; print STDERR "\n\nxml :- >\n" . Dumper($request_xml); __END__ Outputs: IndustryType CurrencyCode CurrencyExponent1 CurrencyExponent2 xml :- > $VAR1 = '<Request> <NewOrder> <IndustryType>EC</IndustryType> <CurrencyCode>840</CurrencyCode> <CurrencyExponent1>1</CurrencyExponent1> <CurrencyExponent2>2</CurrencyExponent2> </NewOrder> </Request> ';
    Cheers,
    Rob
      Hi Rob, it working greatly!!!!!!! Now I can move to build the gateway request easily. Thanks and Cheers.... Sham.