in reply to Yet another XML::Simple question!
Your syntax for calling XMLout is wrong. It's just print XMLout($xml);.
The reason it's printing wrong is that your structure is wrong. You have:
'phonenumbers' => [ # <- Repeats phonennumbers { 'phonenumber' => { 'number' => '9163723752' } }, { 'phonenumber' => { 'number' => '9166413900' } } ]
You need:
'phonenumbers' => [ # <- Repeats phonennumbers { 'phonenumber' => [ # <- Repeats phonennumber { 'number' => '9163723752' }, { 'number' => '9166413900' } ] } ]
For example:
>type !.xml <campaign action="0" menuid="10118"> <phonenumbers> <phonenumber number="9163723752" /> <phonenumber number="9166413900" /> </phonenumbers> </campaign> >type !.pl use XML::Simple qw( XMLin XMLout ); # It didn't think "!.xml" was a file name until I added "./". # Options were lowercase in older versions (like the one I have. my $xml = XMLin('./!.xml', keeproot => 1, forcearray => 1); print XMLout($xml, keeproot => 1); >perl !.pl <campaign menuid="10118" action="0"> <phonenumbers> <phonenumber number="9163723752" /> <phonenumber number="9166413900" /> </phonenumbers> </campaign>
Update: Sorry, I was familiar with the OO calling syntax. My initial paragraph was wrong, but the rest still applies.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Yet another XML::Simple question!
by jdtoronto (Prior) on Jul 19, 2005 at 20:05 UTC | |
by ikegami (Patriarch) on Jul 19, 2005 at 20:10 UTC |