#!/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'); }