Give this a try for starters.
#!/usr/bin/perl
use strict;
use XML::LibXML;
my $xml2 = XML::LibXML->new();
my $data = $xml2->parse_file("adi.xml");
foreach my $test ($data->findnodes('//Metadata')) {
if ($test->findnodes('./ADI/@Name[.="movie"]')){
print "movie\n";
}
elsif ($test->findnodes('./ADI/@Name[.="photo"]')){
print "photo\n";
}
elsif ($test->findnodes('./ADI/@Name[.="poster"]')){
print "poster\n";
}
}
There is no findvalues
method. What you want to do is use findnodes
, which will return to you a list of nodes matching the XPath expression. Once you have that, you can iterate over the list and extract any of the data you need, much like you're already doing for Metadata
.
Also, I'm assuming your XML file has a single root-level element. I used the modified version below to test the above code.
<root>
<Metadata>
<ADI Name="movie" />
<App_Data Name="Something I don't care about" value="who cares" />
<App_Data Name="Something I don't care about as well" value="who cares" />
<App_Data Name="ChangeMe" Value="" />
</Metadata>
<Metadata>
<ADI Name="photo" />
<App_Data Name="Something I don't care about" value="who cares" />
<App_Data Name="Something I don't care about as well" value="who cares" />
<App_Data Name="ChangeMe" Value="" />
</Metadata>
<Metadata>
<ADI Name="poster" />
<App_Data Name="Something I don't care about" value="who cares" />
<App_Data Name="Something I don't care about as well" value="who cares" />
<App_Data Name="ChangeMe" Value="" />
</Metadata>
</root>
I find this cheatsheet useful for Perl's LibXML library.