er20 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use XML::Twig; while(<DATA>) { chop;$data.= $_; } #get all <class>s with the attribute "name='Item'" $path = "class[\@name='Item']"; print "PATH: " . $path . "\n"; testPa +th($path); #works #get all <function>s who's parents are <class> $path = "class/function"; print "PATH: " . $path . "\n"; testPath($pa +th); #works #get all <function>s who's parents are <class> with the attribute "nam +e='Item'" $path = "class[\@name='Item']/function"; print "PATH: " . $path . "\n +"; testPath($path); #doesn't work #get all <function>s that have the attribute "name='SAVE_ITEM'" and wh +o's parents are <class> $path = "class/function[\@name='SAVE_ITEM']"; print "PATH: " . $path +. "\n"; testPath($path); #doesn't work #get all <function>s that have the attribute "name='SAVE_ITEM'" and wh +o's parents are <class> with the attribute "name='Item'" $path = "class[\@name='Item']/function[\@name='SAVE_ITEM']"; print "PA +TH: " . $path . "\n"; testPath($path); #doesn't work print "\n\nD0NE"; # the 3rd, 4th, and 5th calls to testPath() produce the following erro +rs, respectively: # " unrecognized expression in handler: 'class[@name='Item']/function' + at testTwig.pl line 32 " # " unrecognized expression in handler: 'class/function[@name='SAVE_IT +EM']' 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__ <objects> <class name="Item" > <function name="LOAD_ITEM" > </function> <function name="SAVE_ITEM" > </function> </class> <class name="Item2" > <function name="LOAD_ITEM" > </function> </class> </objects>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig "unrecognized expression in handler:"
by mirod (Canon) on Jul 28, 2007 at 01:42 UTC | |
by Anonymous Monk on Jul 30, 2007 at 00:15 UTC |