Search code examples
perlxml-simple

The xml attribute "id" seems to be a protected attribute. What config needed to be able to set it?


I am using the perl module XML::Simple to create an XML structure. Everything works fine except that the string "<tag1 id="5"> ABC </tag1>" looks like <tag1 name="5"> ABC </tag1> afterwards.

I use the string with XML::Simple as follows

my $simple = XML::Simple->new();
my $tree = $simple->XMLin($my_xml_string, ForceArray => 1);

$resp->data()->{'xml'} = $tree;

The xml attribute id seems to be a protected attribute, because i get name in the output .

What config is needed to be able to set it?


Solution

  • Look at the KeyAttr option. You probably want KeyAttr => [] to de-activate array to hash folding