Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Challenge: Parse XML Feed for Youtube channel -- Mojo::DOM

by LanX (Saint)
on Jun 29, 2022 at 11:05 UTC ( [id://11145171]=note: print w/replies, xml ) Need Help??


in reply to Re: Challenge: Parse XML Feed for Youtube channel -- Mojo::DOM
in thread Challenge: Parse XML Feed for Youtube channel

Here a new approach with Mojo::DOM and taking benefit from it's overloading to shorten ->text and ->attr methods away.

Also using an own rolled "template system" for readability

The explicit map in the callback might also be easier done with an Mojo::DOM method ... maybe?

use v5.12; use warnings; use Mojo::DOM; my $data = join "", <DATA>; my $dom = Mojo::DOM->new($data); say &t::page( TITLE => $dom->at('title'), NAME => $dom->at('name'), ENTRIES => \&entries, ); sub entries { map { t::entry ( TITLE => $_->at("title"), HREF => $_->at("link")->{href}, DESC => $_->at('media\:group > media\:description') ); } $dom->find('entry')->each ; } package t; # poor man's templates sub page { my %p = @_; << "____" } <h3>$p{ TITLE }</h3> <b>$p{ NAME }</b> <ul> @{[ $p{ ENTRIES }->() ]} </ul> ____ sub entry { my %p = @_; << "____" } <li>[$p{ HREF }|$p{ TITLE }]<p> $p{ DESC } </li> ____ package main;

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found