Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

RSS finding date of publication using XML::Feed

by mldvx4 (Scribe)
on Sep 11, 2019 at 13:40 UTC ( #11106027=perlquestion: print w/replies, xml ) Need Help??

mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:

I have encountered an RSS2 feed which fails in the module XML::Feed in regards to finding the datestamp of each entry, either modfied or issued. The feed itself seems to have "PubDate" in the entries, but I am not finding that with XML::Feed or else I am using XML::Feed incorrectly. I've reproduced a stripped down version of it below. How would I find the publication date for the single entry as shown in the demo below?

#!/usr/bin/perl use XML::Feed; use strict; use warnings; my $feed = XML::Feed->parse(\*DATA) or die XML::Feed->errstr; print $feed->title, "\n"; for my $entry ($feed->entries) { print "T=", $entry->title, "\n"; print "\tM=", $entry->modified||$entry->issued, "\n"; } exit(0); __DATA__ <rss xmlns:dc="" version="2.0"> <channel> <title><![CDATA[ foo bar one ]]></title> <link></link> <description/> <language>en</language> <copyright>foo bar</copyright> <ttl>120</ttl> <item> <title><![CDATA[ Foo Bar Two ]]></title> <link></link> <description><![CDATA[ <p align="center"> <span style="font-size: 0.75em;"> </span></p> <p>words words words</p> ]]></description> <pubDate>2019-09-10 13:38:00</pubDate> <guid isPermaLink="false"></guid> <dc:creator>foo bar three</dc:creator> </item> </channel> </rss>

Replies are listed 'Best First'.
Re: RSS finding date of publication using XML::Feed
by poj (Abbot) on Sep 11, 2019 at 14:13 UTC


    printf "%s\n", $entry->{entry}{pubDate};


      Thanks. That does the trick, but may I ask how did you find that? I presume it can be inferred from somewhere within the module's source. It was not in the manual page at all.

        I used Data::Dump to inspect the structure of $element

        use Data::Dump 'pp'; my $feed = XML::Feed->parse(\*DATA) or die XML::Feed->errstr; for my $entry ($feed->entries) { pp $entry; }
        bless({ _version => "2.0", entry => { "dc" => { creator => "foo bar three" }, "description" => " <p align=\"center\">\n<span style=\"font-size: +0.75em;\"> </span></p>\n<p>words words words</p> ", "guid" => "", "" => { creator => "foo bar three" + }, "isPermaLink" => "", "item" => "\n\n\n\n\n\n\n", "link" => "", "pubDate" => "2019-09-10 13:38:00", "title" => " Foo Bar Two ", }, }, "XML::Feed::Entry::Format::RSS")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11106027]
Approved by Perlbotics
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2019-12-06 02:17 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (154 votes). Check out past polls.