Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Xml::Twig:Xpath Xpath expression error

by leonidlm (Pilgrim)
on Apr 16, 2009 at 11:48 UTC ( [id://757947]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Xml::Twig:Xpath Xpath expression error
in thread Xml::Twig:Xpath Xpath expression error

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

Replies are listed 'Best First'.
Re^5: Xml::Twig:Xpath Xpath expression error
by mirod (Canon) on Apr 16, 2009 at 11:57 UTC

    Don't use get_xpath, use findnodes, as the docs state:

    XML::Twig does not provide natively full XPATH support, but you can use "XML::Twig::XPath" to get "findnodes" to use "XML::XPath" as the XPath engine, with full coverage of the spec.

    Actually the development version of XML::Twig produces the following message in that situation:

    error in xpath expression //OverallConnectionPoolStatus/FlowRater/Name/text() around text() the expression is a valid XPath statement, and you are using XML::Twig::XPath, but you are using either 'find_nodes' or 'get_xpath' where the method you likely wanted to use is 'findnodes', which is the only one that uses the full XPath engine

      Ohhh, now it is working!
      BTW thank you for the wonderful module. It really helping me in saving much more on performance when I am processing big XML files.
      Just a small suggestion, maybe in a new version (or just in the docs) somehow make this more understandable for others, who would like to use this module in a future. Maybe to change the method name to "findnodesWithXpath" or something ...
      but anyway, thank you again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://757947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-19 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found