trebork has asked for the wisdom of the Perl Monks concerning the following question:
Which ouputs this.#!/usr/bin/perl -w use strict; use Data::Dumper; use XML::Twig; my $twig= new XML::Twig; my $xml=qq~<RateInfo> <displayCurrencyCode>USD</displayCurrencyCode> <DisplayNightlyRates size=\'3\'> <displayNightlyRate>298.95</displayNightlyRate> <displayNightlyRate>298.95</displayNightlyRate> <displayNightlyRate>348.95</displayNightlyRate> </DisplayNightlyRates> <displayRoomRate>1106.62</displayRoomRate> <chargeableRoomRateTotal>1106.62</chargeableRoomRateTotal> <chargeableRoomRateTaxesAndFees>159.77</chargeableRoomRateTaxe +sAndFees> <nativeCurrencyCode>USD</nativeCurrencyCode> <NativeNightlyRates size=\'3\'> <nativeNightlyRate>298.95</nativeNightlyRate> <nativeNightlyRate>298.95</nativeNightlyRate> <nativeNightlyRate>348.95</nativeNightlyRate> </NativeNightlyRates> <nativeRoomRate>1106.62</nativeRoomRate> <rateFrequency>B</rateFrequency> </RateInfo>~; $twig->parse($xml); # build the twig my $struct = $twig->simplify( forcearray => 1 ); print Dumper $struct;
I have tried working with GroupTags and KeyAttr in the simplify function but have been unable to make a dent in he output. Can this be done via twig and simplify(); Or do I have to manipulate $struct directly? Thanks$VAR1 = { 'nativeCurrencyCode' => [ 'USD' ], 'displayCurrencyCode' => [ 'USD' ], 'chargeableRoomRateTaxesAndFees' => [ '159.77' ], 'rateFrequency' => [ 'B' ], 'chargeableRoomRateTotal' => [ '1106.62' ], 'NativeNightlyRates' => [ { 'nativeNightlyRate' => [ '298.95', '298.95', '348.95' ], 'size' => '3' } ], 'DisplayNightlyRates' => [ { 'size' => '3', 'displayNightlyRate' => [ '298.95', '298.95', '348.95' ] } ], 'displayRoomRate' => [ '1106.62' ], 'nativeRoomRate' => [ '1106.62' ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig handling arrays
by mirod (Canon) on Dec 02, 2008 at 09:48 UTC | |
|
Re: XML::Twig handling arrays
by poolpi (Hermit) on Dec 02, 2008 at 09:09 UTC | |
|
Re: XML::Twig handling arrays
by Jenda (Abbot) on Dec 02, 2008 at 14:50 UTC |