1 2 3 4 5 6 7 8 9
use XML::Simple; my $xs = XML::Simple->new(); my $ref = $xs->XMLin('test.xml'); for my $mandant (@{$ref->{Company}}) { print $mandant->{ID}."\n"; print $mandant->{Name}."\n"; }
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<License xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Company>
<ID>100</ID>
<Name>Mandant 1</Name>
</Company>
<Company>
<ID>110</ID>
<Name>Mandant 2</Name>
</Company>
</License>
error:Not an ARRAY reference
print $ref->{Company}->{ID};
error:Not a HASH reference
QuoteForceArray => 1 # in - important
This option should be set to '1' to force nested elements to be represented as arrays even when there is only one.
ForceArray => [ names ] # in - important
This alternative (and preferred) form of the 'ForceArray' option allows you to specify a list of element names which should always be forced into an array representation