"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.
Contents of pm_1082058_n4000-small.xml:
<formation name="stoneridge" version="1.6">
<block>
<matrix>
<vm type="sns">
<release version="8.5.e">
<supported>
<fixed>123.1106</fixed>
</supported>
</release>
</vm>
<vm type="br">
<release version="7.2.2">
</release>
</vm>
</matrix>
<notmatrix>
<vm type="sns">
<release version="4.1.e">
<supported>
<min>124.1306</min>
<max>124.1500</max>
</supported>
</release>
</vm>
<vm type="br">
<release version="7.2.1" wanted="NO">
</release>
</vm>
</notmatrix>
<matrix>
<vm type="sns">
<release version="4.1.e">
<supported>
<min>124.1306</min>
<max>124.1500</max>
</supported>
</release>
</vm>
<vm type="br">
<release version="7.2.1" wanted="YES">
</release>
</vm>
</matrix>
</block>
</formation>
|