programming-examples/perl/XML/Check node name in SAX paser.pl

30 lines
524 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
use XML::Parser;
$parser = new XML::Parser(Handlers => {Start => \&start_handler, Char => \&char_handler});
$parser->parsefile("yourXML.xml");
$customer = 0;
$data_ok = 0;
sub start_handler
{
$data_ok = 0;
if ($_[1] eq "tagName"){
$customer++;
}
if ($customer == 2){
if($_[1] eq "tagName2"){
$data_ok++;
}
}
}
sub char_handler
{
if(($_[1] =~ /[^ \n\t\r]/g) && $data_ok){
print "First name: $_[1]\n";
}
}