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' => \§ion,
});
$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 ?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.