Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RSS finding date of publication using XML::Feed

by mldvx4 (Friar)
on Sep 11, 2019 at 17:40 UTC ( [id://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="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title><![CDATA[ foo bar one ]]></title> <link>https://example.org/rss2.xml</link> <description/> <language>en</language> <copyright>foo bar</copyright> <ttl>120</ttl> <item> <title><![CDATA[ Foo Bar Two ]]></title> <link>https://www.example.org/</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">https://example.org/</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 18:13 UTC

    Try

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

    poj

      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; }
        outputs
        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" => "https://example.org/", "http://purl.org/dc/elements/1.1/" => { creator => "foo bar three" + }, "isPermaLink" => "", "item" => "\n\n\n\n\n\n\n", "link" => "https://www.example.org/", "pubDate" => "2019-09-10 13:38:00", "title" => " Foo Bar Two ", }, }, "XML::Feed::Entry::Format::RSS")
        poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found