Hello LanX,

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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.