oh gee I forgot how ugly can be to handle XML! So as I was used to XML::Twig (last update 2016! fear!) I propose you a quite old style brute force attack approach. It works as expected. Here is too hot to also venturing into template systems.. heredoc are enough :)
use strict; use warnings; use LWP::UserAgent; use XML::Twig; binmode(STDOUT, "encoding(UTF-8)"); my $xml = LWP::UserAgent->new->get('https://www.youtube.com/feeds/vide +os.xml?playlist_id=PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE')->decoded_cont +ent; my ($title_title, $title_name, @elements); my $twig= XML::Twig->new( twig_handlers=>{ '/feed/title' =>sub{ $title_title = $_[1]->t +ext }, '/feed/author/name' =>sub{ $title_name = $_[1]->t +ext }, '/feed/entry' =>sub{ my @found; push @found, $_[1]->first_child('title' +)->text, ( split ':',$_[1]->first_c +hild('id')->text)[2]; # damn schema prefix i cant get rid of + it without this ugly... for ($_[1]->descendants ){push @found, + $_->text if $_->gi eq 'media:description'} push @elements,\@found; + }, } ); $twig->parse($xml); print <<"EOT"; <h3> $title_title </h3> <b>$title_name</b> <ul> EOT foreach my $ele (@elements){ print <<"EOT"; <li> [https://www.youtube.com/watch?v=$ele->[1]|$ele->[0]] <p> <i>$ele->[2]</i></li> EOT } print '</ul>';
L*
In reply to Re: Challenge: Parse XML Feed for Youtube channel -- XML::Twig
by Discipulus
in thread Challenge: Parse XML Feed for Youtube channel
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |