for my $para ( $root->children('para') ) {
if ( $para->first_child_matches('get_this') ) {
print $para->first_child('get_this')->att('value');
}
}
####
use strict;
use warnings;
use XML::Twig;
my $xml = <
0000000000000000000000000000000000000000000XXXXXXX
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
1111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222
3333333333333333333333333333333333333333333
4444444444444444444444444444444444444444444
5555555555555555555555555555555555555555555
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
does this work
XML
my $tmp = XML::Twig->new();
$tmp->parse ($xml);
my $root = $tmp->root;
print "Here is XML file \n" . $xml . "\n";
print ">>>>>>>>>> children of when 'para' is root<<<<<<<<<<<<<\n";
print $_->trimmed_text (), "\n" for $root->children ('para');
print ">>>>>>>>>> first_child of when 'para' is root <<<<<<<<<<<<<\n";
print $_->text (), "\n" for $root->first_child ('para');
print ">>>>>>>>>> last_child of when 'para' is root <<<<<<<<<<<<<\n";
print $_->text (), "\n" for $root->last_child('para');
print ">>>>>>>>>> children of when 'para_4th' is root<<<<<<<<<<<<<<<\n";
print $_->text (), "\n" for $root->last_child('para')->first_child('para_4th');
print ">>>>>>>>>> find att 'eff' value from para_4th <<<<<<<<<<<<<\n";
print $_, "\n" for $root->last_child('para')->first_child('para_4th')->att('eff');
print ">>>>>>>>>> children of when 'para' is root find value of id<<<<<<<<<<<<<<<<<<\n";
#print $_, "\n" for $root->children('para')->att('id');
for my $para ( $root->children('para') ) {
print $para->att('id') . "\n";
}
for my $para ( $root->children('para') ) {
if ( $para->first_child_matches('get_this') ) {
print $para->first_child('get_this')->att('value');
}
}
####
Here is XML file
0000000000000000000000000000000000000000000XXXXXXX
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
1111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222
3333333333333333333333333333333333333333333
4444444444444444444444444444444444444444444
5555555555555555555555555555555555555555555
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
does this work
>>>>>>>>>> children of when 'para' is root<<<<<<<<<<<<<
0000000000000000000000000000000000000000000XXXXXXX ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
1111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222
3333333333333333333333333333333333333333333
4444444444444444444444444444444444444444444
5555555555555555555555555555555555555555555
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX does this work
>>>>>>>>>> first_child of when 'para' is root <<<<<<<<<<<<<
0000000000000000000000000000000000000000000XXXXXXX ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
>>>>>>>>>> last_child of when 'para' is root <<<<<<<<<<<<<
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
does this work
>>>>>>>>>> children of when 'para_4th' is root<<<<<<<<<<<<<<<
does this work
>>>>>>>>>> find att 'eff' value from para_4th <<<<<<<<<<<<<
no
>>>>>>>>>> children of when 'para' is root find value of id<<<<<<<<<<<<<<<<<<
000
111
222
333
444
555
XXX