I try to call a routine for each tag, but it end_tag_handlersnever gets called.
My goal is the sequence:
--- sequence ---
when <auto>call \&loading.
when a <apps><title>call \&kicks.
when a <apps><logs>call \&bye.
when called <apps> \&app.
when a <apps><title>call \&kicks.
when a <apps><logs>call \&bye.
when called <apps> \&app.
when </auto>call \&finish. → He was not called.
temp.pl:
use XML::Twig;
my $twig = XML::Twig->new(
start_tag_handlers =>
{ 'auto' => \&loading
},
twig_handlers =>
{ 'apps/title' => \&kicks,
'apps/logs' => \&bye
},
twig_roots =>
{ 'apps' => \&app
},
end_tag_handlers =>
{ 'auto' => \&finish
}
);
$twig -> parsefile( "doc.xml");
sub loading {
print "---loading--- \n";
}
sub kicks {
my ($twig, $elt) = @_;
print "---kicks--- \n";
print $elt -> text;
print " \n";
}
sub app {
my ($twig, $apps) = @_;
print "---app--- \n";
print $apps -> text;
print " \n";
}
sub bye {
my ($twig, $elt) = @_;
print "---bye--- \n";
print $elt->text;
print " \n";
}
sub finish {
print "---fishish--- \n";
}
doc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<auto>
<apps>
<title>watch</title>
<commands>set,start,00:00,alart,end</commands>
<logs>csv</logs>
</apps>
<apps>
<title>machine</title>
<commands>down,select,vol_100,check,line,end</commands>
<logs>dump</logs>
</apps>
</auto>
exit:
C:\>perl temp.pl
watch
csv
watchset,start,00:00,alart,endcsv
machine
dump
machinedown,select,vol_100,check,line,enddump
I would like more here.