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


in reply to Xml::Twig:Xpath Xpath expression error

Er... after looking at it again... you are creating a plain XML::Twig object instead of an XML::Twig::XPath one. I'll have to update the error message in this case.

  • Comment on Re: Xml::Twig:Xpath Xpath expression error

Replies are listed 'Best First'.
Re^2: Xml::Twig:Xpath Xpath expression error
by leonidlm (Pilgrim) on Apr 16, 2009 at 10:32 UTC
    Thank you, I changed it but I still having problems with running even simple expressions. like:
    //OverallConnectionPoolStatus/FlowRater/text()
    why? it appears in XML::XPath examples as valid syntax!

      The thing is, there is no direct textual content in any of the FlowRater elements, so text() is empty, hence //OverallConnectionPoolStatus/FlowRater/text() won't return much.

      //OverallConnectionPoolStatus/FlowRater/Name/text() OTOH, will indeed give you the contents of the Name elements, if you write, for example: print map { $_ } $section->findnodes( q{//OverallConnectionPoolStatus/FlowRater/Name/text()} );.

        Thank you. I tried that. The returned output is again, as before, a syntax error:
        error in xpath expression //OverallConnectionPoolStatus/FlowRater/Name +/text() ar ound text() at D:\Scripts\prun84\test3.pl line 27 at D:\Scripts\prun84\test3.pl line 8 at D:\Scripts\prun84\test3.pl line 8
        You said it won't do much, but it shouldn't crash with an error if the expression will return nothing! I think there is a problem somehow with loading the XML::Twig::XPath module, somehow I believe I still using the XML::Twig engine. Can it be ? Just to make sure I attach the full program:
        use XML::Twig::XPath; my $t = XML::Twig::XPath->new( twig_roots => { 'BalancerStatus/WebServer/OverallConnectionPoolStatus' => +\&section, #'BalancerStatus/WebServer/BalancerStatus/Server' => \&sec +tion }); $t->parsefile( 'localhost.xml'); # sub section { my ($t, $section) = @_; my $a = $section->get_xpath( q{//OverallConnectionPoolStatus/FlowR +ater/Name/text()} ); $t->purge; }