http://qs321.pair.com?node_id=757368

leonidlm has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
I have a strange problem. Please inspect the following code:
use XML::Twig::XPath; my $t = XML::Twig->new( twig_roots => { 'BalancerStatus/WebServer/OverallConnectio +nPoolStatus' => \&section, }); $t->parsefile( 'localhost.xml'); # sub section { my ($t, $section) = @_; print $section->get_xpath( q{//OverallConnectionPoolStatus/FlowRat +er[Name='Total.IncomingReq']} ); $t->purge; }
When I run it on an xml file I receive:
error in xpath expression //OverallConnectionPoolStatus/FlowRater[Name= ...
I decided to check this exact expression in the XML::XPath itself, and there, I have no errors, I even get a desired result! I used the following code:
use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => 'chunk.xml'); my $nodeset = $xp->find( q{//OverallConnectionPoolStatus/FlowRater +[Name='Total.IncomingReq']} ); # find all paragraphs foreach my $node ($nodeset->get_nodelist) { print "FOUND\n\n", XML::XPath::XMLParser::as_string($node), "\n\n"; }
Strange! Can someone help ?