in reply to LibXML: Can't get value

You can use logical operators on the attributes.

#!/usr/bin/env perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => 'imgfile.xml'); say 'XML Version is: ', $dom->version; say 'Document encoding is: ', $dom->encoding; my $query = '(@name="Name" and @class="FILENAME") or (@name="Size")'; my $xpath = '/files/file[@name="Image"]/item/field['.$query.']'; for my $node ( $dom->findnodes($xpath) ) { print "\n"; say 'Name : ', $node->getAttribute('name'); say 'Class : ', $node->getAttribute('class'); say 'Value : ', $node->getAttribute('value'); }
poj

Replies are listed 'Best First'.
Re^2: LibXML: Can't get value
by Anonymous Monk on Mar 17, 2017 at 01:47 UTC

    Hi,

    You can use also whitespace in xpath

    my $xpath = q{ /files /file[@name="Image"] /item/field[ ( @name="Name" and @class="FILENAME" ) or @name="Size" ] }; for my $node ( $dom->findnodes($xpath) )