Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
"Fwiw the change of quoting you suggested doesn't actually fix my mistake."

My apologies if the change in quoting was misinterpreted as part of the fix.

The change from //vm to //matrix/vm was the fix.

You had multiple instances of \' and \@ (within double-quoted strings) throughout your post: the quoting change was a cure for backslashitis. :-)

Here's the test I ran prior to posting:

#!/usr/bin/env perl -l use strict; use warnings; use XML::LibXML; my $file = 'pm_1082058_n4000-small.xml'; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($file); for my $vm ($doc->findnodes('//matrix/vm[@type="br"]')) { my $version = $vm->findvalue('./release/@version'); print 'Version: ', $version; print 'Wanted: ', $vm->findvalue('./release/@wanted'); if ($version eq '7.2.1') { print 'Found!'; last; } }

Output:

Version: 7.2.2 Wanted: Version: 7.2.1 Wanted: YES Found!

As you can see, there's no backslashes here at all (which I find makes the code more readable). The '//matrix/vm[@type="br"]' solution which I posted in my original reply was copied directly from that. If you want to run that test (or modifiy it for other tests), the data I used (pm_1082058_n4000-small.xml) is in the spoiler below.

-- Ken


In reply to Re^3: xpath problem using XML::LibXML by kcott
in thread xpath problem using XML::LibXML by anadem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found