#!/usr/bin/perl use XML::Twig; while() { chop;$data.= $_; } #get all s with the attribute "name='Item'" $path = "class[\@name='Item']"; print "PATH: " . $path . "\n"; testPath($path); #works #get all s who's parents are $path = "class/function"; print "PATH: " . $path . "\n"; testPath($path); #works #get all s who's parents are with the attribute "name='Item'" $path = "class[\@name='Item']/function"; print "PATH: " . $path . "\n"; testPath($path); #doesn't work #get all s that have the attribute "name='SAVE_ITEM'" and who's parents are $path = "class/function[\@name='SAVE_ITEM']"; print "PATH: " . $path . "\n"; testPath($path); #doesn't work #get all s that have the attribute "name='SAVE_ITEM'" and who's parents are with the attribute "name='Item'" $path = "class[\@name='Item']/function[\@name='SAVE_ITEM']"; print "PATH: " . $path . "\n"; testPath($path); #doesn't work print "\n\nD0NE"; # the 3rd, 4th, and 5th calls to testPath() produce the following errors, respectively: # " unrecognized expression in handler: 'class[@name='Item']/function' at testTwig.pl line 32 " # " unrecognized expression in handler: 'class/function[@name='SAVE_ITEM']' at testTwig.pl line 32 " # " unrecognized expression in handler: 'class[@name='Item']/function[@name='SAVE_ITEM']' at testTwig.pl line 32 " sub testPath { print "\nOUTPUT START_______________________\n"; my $p = XML::Twig->new(PrettyPrint => 'record',twig_handlers =>{$path => sub { handler($_); } } ); $p->parse( $data ); print "\nOUTPUT END_______________________\n\n"; } sub handler { ($node) = @_; $node->print; } __END__