in reply to XML::Simple help please

If you pass ForceArray to XMLin() you should get equivalent XML for both $xml_src and $xml_out e.g
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, ForceArray => 1); my $xml_out = XMLout(Test(), rootname=>'foo'); 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; } __output__ Source: <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> Output: <foo> <bar> <number>1</number> <barfoo>Goodbye world</barfoo> <foobar>Hello world</foobar> </bar> <bar> <number>2</number> <barfoo>def</barfoo> <foobar>abc</foobar> </bar> </foo>
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: XML::Simple help please
by eric256 (Parson) on Apr 30, 2004 at 13:11 UTC

    On my system XML::Simple requires ForceArray to be forcearray all lower case. I don't know if thats a 'feature' of my version or if its the intended behaviou. I know the docs show it with capitals so just be warned that doesn't work in some places.

    update: I seem to have version 1.06 which is old. hmm off to update it :)


    ___________
    Eric Hodges