Check node name in SAX paser : SAX « XML « Perl






Check node name in SAX paser

   

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";
    }
}

   
    
    
  








Related examples in the same category

1.Check error in SAX parser
2.Register handlers to SAX parser
3.SAX parser handler
4.Converting a comma separated list data source to XML
5.Stream XML::Parser
6.The XML::Parser module provides a framework for parsing XML.
7.Using XML::Parser to parse xml file
8.Using XML:Simple to read and store the document
9.XML::Parasr style: Tree