hi ,
I am using XML::twig for parsing XML file thru perl.
xml code:- ex1.xml
<stats>
<player>
<a>
<name>Houston,Allan</name>
<p>20.1</p>
</a>
<a>
<name>Sprewell, Latrell</name>
<p>19.2</p>
</a>
<a>
<name>Ewing,Patrick</name>
<p>14.6</p>
</a>
</player>
</stats>
Perl code:-
use strict;
use XML::Twig;
my $twig= new XML::Twig;
$twig->parsefile( "ex1.xml");
my $root= $twig->root;
my
@players= $root->children;
foreach my $player (
@players) {
my
@aaa=$player->first_child('a')->children;
foreach my $i (
@aaa){
my $name=$i->first_child('name')->text; ****
my $p=$i->first_child('p')->text;
print $name.$p;
}
}
My required output is :-
Houston,Allan 20.1
Sprewell, Latrell 19.2
Ewing,Patrick 14.6
but if i write the line marked *** as :-
my $name=$i->first_child()->text;
it is fetching the values of first set of <a>
but i want to iterate thru the loop and print all the values in <a> in name.p format.
can any one help me in this?
thanks in advance,
regards,
chakri