user2013387
user2013387

Reputation: 203

XML::Simple removes root element

Hi I have a xml data which i get from array of hashes and when I do a Dumper on it the output is as follows:

$var1=
    '<Data>
            <Data1>ABC</Data1>
            <Data2>ABCD</Data2>
    </Data>';

This I have in a variable call $var1. Now I am using XML::Simple on it.. it is somewhat like: {Data1=>'ABC',Data2=>'ABCd'};

The first tag Data is gone. What is wrong?

Upvotes: 2

Views: 684

Answers (1)

Anton Kovalenko
Anton Kovalenko

Reputation: 21517

Seems to be well-documented:

KeepRoot => 1:

In its attempt to return a data structure free of superfluous detail and unnecessary levels of indirection, XMLin() normally discards the root element name. Setting the KeepRoot option to 1 will cause the root element name to be retained. So after executing this code:

     $config = XMLin('<config tempdir="/tmp" />', KeepRoot => 1)

You'll be able to reference the tempdir as "$config->{config}->{tempdir}" instead of the default "$config->{tempdir}".

Upvotes: 7

Related Questions