Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Atom Feed for Chatterbox 60

by tobyink (Abbot)
on Oct 14, 2012 at 10:04 UTC ( #998947=CUFP: print w/replies, xml ) Need Help??

#!/usr/bin/env perl use HTML::HTML5::Parser; use Object::Tap -package => 'XML::Atom::Base'; use XML::Atom::Feed; use XML::Atom::Entry; use XML::Atom::Person; use XML::LibXML 2.00; my $list = HTML::HTML5::Parser -> new -> parse_file('', { ignore_http_respo +nse_code => 1 }) -> getElementsByTagName('dl') -> get_node(1); my $feed = XML::Atom::Feed->new; $feed->title('PerlMonks Chatterbox'); $feed->id(',2012:perlmonks:chatterbox'); my $dt; foreach my $node ($list->getChildrenByTagName('*')) { ($dt = $node) && next if $node->tagName eq 'dt'; $feed->add_entry( XML::Atom::Entry->new->tap( title => [ $node->textContent ], id => [ join ':', $feed->id, $dt->{id} ], author => [ XML::Atom::Person->new->tap( name => [ $dt->getElementsByTagName('a')->get_node +(1)->textContent ], uri => [ ''. $dt->getElementsByTagName('a')->get_node(1)->{ +href} ], ) ], published => [ $dt->getElementsByTagName('small')->get_node(1)->textC +ontent, ], ) ); } print $feed->as_xml;

Fixing up the datetimes to meet the Atom 1.0 spec is left as an exercise for the reader.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re: Atom Feed for Chatterbox 60
by mje (Curate) on Oct 15, 2012 at 13:16 UTC

    Thanks tobyink. I had to make a slight change for behind a proxy server:

    my $ua = LWP::UserAgent->new; $ua->env_proxy; my $list = HTML::HTML5::Parser -> new -> parse_file('', { ignore_http_respo +nse_code => 1, user_agent => $ua }) -> getElementsByTagName('dl') -> get_node(1);

    Also, HTML::HTML5::Parser failed its tests for me. When I looked at the test results I saw other people/smokers had hit this too so I reported it at 07ua.t fails.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://998947]
Approved by moritz
[Corion]: Oooh - I had another devious idea - "Host C" - a C language where every struct is 4K in size. This makes memory and disk access incredibly fast ;)
[Corion]: (because everything is aligned to a memory page and all pages can be read+written directly from disk without buffering)

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2017-04-25 09:02 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (449 votes). Check out past polls.