Do not beat me, this is my first experience with that module :>)
#!/usr/bin/perl
use strict;
use XML::XPath;
my $xml = '
<status>
<some_node/>
<connector name="http-0">
<threadInfo currentThreadsBusy="0"/>
<requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTim
+e="0" processingTime="0" requestCount="0"/>
<workers></workers>
</connector>
<connector name="http-8080">
<threadInfo currentThreadCount="158" currentThreadsBusy="10" maxTh
+reads="200"/>
<requestInfo bytesReceived="297" bytesSent="19350704517" errorCoun
+t="192504" maxTime="249349" processingTime="2242513592" requestCount=
+"983650"/>
<workers>
</workers>
</connector>
</status>
';
my $path = '/status/connector/threadInfo/@currentThreadsBusy';
my $xpath = XML::XPath->new( xml => $xml );
my $nodeset = $xpath->find($path);
foreach my $node ($nodeset->get_nodelist) {
print "FOUND: ",
$xpath->getNodeText($node),
"\n";
my $ret = '/@currentThreadsBusy';
my $parent = $node->getParentNode();
while ($parent and $parent->getParentNode()) {
#$ret = '['.$xpath->find('position()',$parent)->value.']' . $ret;
$ret = '['.($xpath->find('preceding-sibling::*[name()="'.$parent->
+getName().'"]',$parent)->size+1).']' . $ret;
$ret = '/'.$parent->getName() . $ret;
$parent = $parent->getParentNode();
}
print $ret."\n";
}
I think that commented row which uses position() would work, but it does not...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|