in reply to xpath problem using XML::LibXML

advice 1) perlquote + xpather.pl

advice 2) line up your xpaths by / and study the xpather full paths :) like this

#!/usr/bin/perl -- use strict; use warnings; use XML::LibXML; my $dom = XML::LibXML->new( qw/ recover 2 / )->load_xml( location => 'pm1082058.xml', ); for my $matrix ( $dom->findnodes( q{ //matrix/vm[@type='br'] } )) { print $matrix->nodePath, "\n"; print "\n$matrix\n\n"; #~ for my $version ( $matrix->findnodes('./vm/release/@version') ) +{ for my $version ( $matrix->findnodes('./release/@version') ){ print $version->nodePath, "\n"; print "$version\n"; } print "\n\n"; } __END__ /formation/block/matrix[1]/vm[2] <vm type="br"> <release version="7.2.2"> </release> </vm> /formation/block/matrix[1]/vm[2]/release/@version version="7.2.2" /formation/block/matrix[2]/vm[2] <vm type="br"> <release version="7.2.1"> </release> </vm> /formation/block/matrix[2]/vm[2]/release/@version version="7.2.1"

As you can see vm doesn't have vm children

//matrix/vm[@type='br'] ./vm/release

Replies are listed 'Best First'.
Re^2: xpath problem using XML::LibXML
by anadem (Scribe) on Apr 12, 2014 at 17:47 UTC

    Thank you kind Anonymous Monk for the excellent pieces of advice, which I shall take to heart. And thank you for pointing out my error and its solution.

    Quoting is one of my may weak points in perl, which I'll correct. The nodePath method will be very useful if I have to work on xml again.