I'm using perl with XML::Simple to print the contents of a XML file. The structure of the XML file however prevents me from listing all entries since I cannot find the right way to loop over the nested arrays. Can anyone help me out and show how to do this?
The XML structure is like:
<header>
<rows>
<row>
<elem>a</elem>
<elem>b</elem>
<elem>c</elem>
</row>
<row>
<elem>d</elem>
<elem>e</elem>
<elem>f</elem>
</row>
</rows>
</header>
My program is like this:
my $infile = test.xml;
my $xml = new XML::Simple (KeyAttr=>[]);
my $main = $xml->XMLin("$infile",SuppressEmpty => '');
I can print separate entries of elem using
print "$main->{rows}->{row}->[0]->{elem}[0]\n";
and print all entries of the n-th elem using
for (@{$main->{rows}{row}}) {
print "$_->{elem}[0] \n";
}
This would print
a
d
But how do I print this:
a;b;c;
d;e;f;
Thanks for any answers.