As an XML/RSS exercise, I wrote up some code that converts the latest questions from the perlmonks Newest Nodes XML Feed to RSS. It's quick and dirty, but works and a script using it is now in my crontab (hourly). (It parses the authors, too, but I haven't done anything with that yet.) I thought other users (or the gods) might be interested in seeing it. People should be able to easily modify this example to pick out other parts of the newest nodes feed if they desire.

use warnings; use strict; use LWP::UserAgent; use XML::Simple; use XML::RSS; # pass in the URL for the newest nodes page, i.e. # http://perlmonks.org/index.pl?node_id=30175 sub process_xml { my $url = shift; my %authors; my @questions; my $browser = LWP::UserAgent->new(); $browser->timeout(30); my $response = $browser->get($url); die unless $response->is_success; my $tree = XMLin( $response->content ); foreach my $node ( @{ $tree->{AUTHOR} } ) { $authors{ $node->{'node_id'} } = $node->{'content'}; } foreach my $node ( @{ $tree->{NODE} } ) { my $item = { author => $authors{ $node->{'author_user'} }, node_id => $node->{'node_id'}, subject => $node->{'content'} }; push @questions, $item if $node->{'nodetype'} eq 'perlquestion +'; } my $rss = new XML::RSS (version => '1.0'); $rss->channel( title => "perlmonks newest questions", link => "http://perlmonks.org", description => "perlmonks newest questions", ); for my $item ( @questions ) { $rss->add_item( title => $item->{subject}, link => "http://perlmonks.org/index.pl?node_id=" . +$item->{node_id} ); } print $rss->as_string(); }

-xdg

Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

DG: Updated to add strict and warnings to set a good example for new monks.


In reply to Code for Perlmonks XML to RSS by xdg

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.