Melly has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monkees,
Actually, put a hold on this for the moment - setting forcearray to 1 seems to resolve my initial problem, but I may be back with further probs. RSN...
With the following code, I want $xml_src and $xml_out to be identical, but everything inside bar ends up as an attribute of bar. What am I doing wrong?
I'm fairly sure that it's to do with needing keyattr and forcearray, but I'm struggling to understand what I'm meant to do...
use strict; use XML::Simple; my $xml_src = '<foo> <bar><number>1</number><foobar>Hello world</foobar><barfoo>Goodbye w +orld</barfoo></bar> <bar><number>2</number><foobar>abc</foobar><barfoo>def</barfoo></bar +> </foo>' ; my $xml_in = XMLin($xml_src, ); my $xml_out = XMLout(Test(), rootname=>'foo'); # how do I make $xml_out == $xml_src ? print "Source:\n" . $xml_src . "\n\n"; print "Output:\n" . $xml_out . "\n"; sub Test{ my $entry; my $out; foreach $entry(@{${$xml_in}{'bar'}}){ push @{${$out}{'bar'}}, $entry; } return $out; }
Can anyone advise?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Simple help please
by broquaint (Abbot) on Apr 30, 2004 at 11:10 UTC | |
by eric256 (Parson) on Apr 30, 2004 at 13:11 UTC | |
|
Re: XML::Simple help please
by gellyfish (Monsignor) on Apr 30, 2004 at 11:06 UTC |