in reply to Keeping XML structure with XML::Simple

I am not really that concerned, as long as the DOM tree still keeps logically equivalent, although you can argure that a child is not a property, but well...

The first thing came up in my mind was this testing, which I felt interesting, mostly triggered by your post:

use XML::Simple; use strict; use warnings; my $xml = XMLin('<config ip="127.0.0.1" port="12345"><timeout>1000</ti +meout><timeout>2000</timeout></config>'); print XMLout($xml);

The output was:

<opt ip="127.0.0.1" port="12345"> <timeout>1000</timeout> <timeout>2000</timeout> </opt>

I am satisfied.

Replies are listed 'Best First'.
Re^2: Keeping XML structure with XML::Simple
by chazzz (Pilgrim) on Jul 21, 2004 at 12:43 UTC
    Are you happy that 'config' was replaced by 'opt'? If that is not the desired behaviour, instead write,
    my $xml = XMLin(..., KeepRoot => 1); print XMLout($xml, KeepRoot => 1);
    which would correctly output:
    <config ip="127.0.0.1" port="12345">
      <timeout>1000</timeout>
      <timeout>2000</timeout>
    </config>
    
    The KeepRoot option tells XML::Simple that your structure already has a root node.
      Just want to point out that the <timeout> element did not get fold up into attributes in your example is because there are more than one of them, by default if there is only one <timeout>, it will be folded up into an attribute.