Hi,
I have this wrapper module for XML::RSS which should serve as an example, was based on the docs from XML::RSS. You could replace the sql used with another data source.

package News::Feed; use CGI; use XML::RSS; use Date::Manip; #Wrapper for XML::RSS sub new { my $class=shift; my $att=shift; my $self={}; bless $self,$class; $self->_init($att); return $self; } sub _init { my $self=shift; my $att=shift; #hardcode 2.0 rss for now $self->{rss} = new XML::RSS (version => '2.0'); $self->{_dbh} = $att->{_dbh}; } sub getHeading { #todo } sub getItems { # For example print out/return the titles and links of each RSS it +em foreach my $item (@{$rss->{'items'}}) { print "title: $item->{'title'}\n"; print "link: $item->{'link'}\n\n"; } } sub createFeedXml { my $self=shift; my $details=shift; #Channel information is required in RSS. The title cannot be more + the 40 characters, the link 500, and the description 500 when output +ting RSS 0.9. #title, link, and description, are required for RSS 1.0. language + is required for RSS 0.91. #validate $self->feedParams () #todo validate input $self->{rss}->channel( title => $details->{title}, link => $details->{link}, description => $details->{description}, dc => { date => $details->{date}, lastBuildDate =>$details->{date}, subject => $details->{subject}, creator => $details->{creator}, publisher => $details->{publisher}, rights => $details->{rights}, language => 'en-us', }, syn => { updatePeriod => "$details->{updatePeriod}", updateFrequency => "1", updateBase => "1901-01-01T00:00+00:00", }, taxo => [ 'http://dmoz.org/Computers/Internet', 'http://dmoz.org/Computers/PC' ] ); } sub addItem { my $self=shift; my $details=shift; $self->{rss}->add_item(title => "$details->{title}", link => "$details->{link}", description=>"$details->{description}" ); } #set the image for the feed sub getImage { my $self=shift; my $details=shift; $self->{rss}->image(title => $details->{title}, url => $details->{imgurl}, link => $details->{link}, width => $details->{width}, height => $details->{height}, description => $details->{description} ); } # Parse raw xml into the XML::RSS object sub parse_sourcexml { my $self=shift; my $sourcexml=shift; $self->{rss}->parse($sourcexml); return $self->{rss}; } # Get the source xml with LWP sub getFeed { my $self=shift; my $sourcelink=shift; $self->{sourcedata} = get($sourcelink); $self->{parsed}=$self->parse($self->{sourcedata}); return $self->{parsed}; } sub writeFeedToDisk { my $self=shift; my $filename=shift; $self->{rss}->save("$filename"); } #feeds that will be generated from our db sub getOutputFeeds { my $self=shift; my $sql="SELECT * FROM news_output_feeds WHERE status='active'"; my $sth=$self->{_dbh}->prepare($sql); $sth->execute(); return $sth->fetchall_arrayref({}); } sub getInputFeeds { my $self=shift; my $sql="SELECT * FROM news_feeds WHERE status='active'"; } sub generateAllOutFeeds { my $self=shift; my $outfeeds=$self->getOutputFeeds(); foreach my $feeddata (@$outfeeds) { $self->generateOutFeed($feeddata); #clear oot rss obj $self->{rss} = new XML::RSS (version => '2.0'); } } sub sanitise { my $string = shift; $string =~ tr/\x91\x92\x93\x94\x96\x97\x19/''""\-\-/; $string =~ s/\x85/.../sg; $string =~ s/\x13//sg; $string =~ tr/[\x80-\x9F]//d; return($string); } sub generateOutFeed { my $self=shift; my $feeddata=shift; #run the sql get the data from db my $sth=$self->{_dbh}->prepare($feeddata->{source_sql_query}); $sth->execute(); use Encode; my $data=$sth->fetchall_arrayref({}); map {$feeddata->{$_}=encode('utf8', decode("ascii", $feeddata->{$_ +})) } keys %$feeddata; map {$feeddata->{$_}=sanitise($feeddata->{$_}) } keys %$feeddata; my $date =UnixDate('today','%a, %d %b %Y %H:%M:%S %Z'); #create channel details my $channeldetails={ title=>$feeddata->{title}, link=>$feeddata->{link}, description=>$feeddata->{description}, date => $date, subject => $feeddata->{subject}, creator => $feeddata->{creator}, publisher => $feeddata->{publisher}, rights => $feeddata->{rights}, }; $self->createFeedXml($channeldetails); # add data to feed foreach my $row (@$data) { map {$row->{$_}=sanitise($row->{$_}) } keys %$row; map {$row->{$_}=encode('utf8', decode("ascii", $row->{$_})) } +keys %$row; $self->addItem($row); } $self->writeFeedToDisk("$feeddata->{filename}"); }

In reply to Re: Seeking advice on generating a syndication feed by hakkr
in thread Seeking advice on generating a syndication feed by fizbin

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.