I am trying to extract node values from an XML file using LibXML. When I call findvalue
all of the nodes of the same element type are concatenated. I am totally
Your input data is not easy to process as was indicated by other posters.
Your code could be as following with provided sample of input data.
use strict;
use warnings;
use feature 'say';
use XML::LibXML;
my $playlistxml = 'playlist.xml';
my $dom = XML::LibXML->load_xml(location => $playlistxml);
foreach my $title ($dom->findnodes('//playlist')) {
say 'Title: ', $title->findvalue('./title');
my $tracks = join "\n", map {
$_->to_literal();
} $title->findnodes('./tracks/track/@id');
say $tracks;
say '';
}
Sample of input data 'playlist.xml'
Yes - Tales From Topographic Oceans
F28F195257143396
Yes - Yessongs
Live Album
405B144877D8B8E4
Output
Title: Yes - Tales From Topographic Oceans
25912
25914
25916
25918
Title: Yes - Yessongs
25920
25922
25924
25926
25928
25930