1XML::Feed(3)          User Contributed Perl Documentation         XML::Feed(3)
2
3
4

NAME

6       XML::Feed - Syndication feed parser and auto-discovery
7

SYNOPSIS

9           use XML::Feed;
10           my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml'))
11               or die XML::Feed->errstr;
12           print $feed->title, "\n";
13           for my $entry ($feed->entries) {
14           }
15
16           ## Find all of the syndication feeds on a given page, using
17           ## auto-discovery.
18           my @feeds = XML::Feed->find_feeds('http://example.com/');
19

DESCRIPTION

21       XML::Feed is a syndication feed parser for both RSS and Atom feeds. It
22       also implements feed auto-discovery for finding feeds, given a URI.
23
24       XML::Feed supports the following syndication feed formats:
25
26       ·   RSS 0.91
27
28       ·   RSS 1.0
29
30       ·   RSS 2.0
31
32       ·   Atom
33
34       The goal of XML::Feed is to provide a unified API for parsing and using
35       the various syndication formats. The different flavors of RSS and Atom
36       handle data in different ways: date handling; summaries and content;
37       escaping and quoting; etc. This module attempts to remove those
38       differences by providing a wrapper around the formats and the classes
39       implementing those formats (XML::RSS and XML::Atom::Feed). For example,
40       dates are handled differently in each of the above formats. To provide
41       a unified API for date handling, XML::Feed converts all date formats
42       transparently into DateTime objects, which it then returns to the
43       caller.
44

USAGE

46   XML::Feed->new($format)
47       Creates a new empty XML::Feed object using the format $format.
48
49           $feed = XML::Feed->new('Atom');
50           $feed = XML::Feed->new('RSS');
51           $feed = XML::Feed->new('RSS', version => '0.91');
52
53   XML::Feed->parse($stream)
54   XML::Feed->parse($stream, $format)
55       Parses a syndication feed identified by $stream and returns an
56       XML::Feed object. $stream can be any one of the following:
57
58       ·   Scalar reference
59
60           A reference to string containing the XML body of the feed.
61
62       ·   Filehandle
63
64           An open filehandle from which the feed XML will be read.
65
66       ·   File name
67
68           The name of a file containing the feed XML.
69
70       ·   URI object
71
72           A URI from which the feed XML will be retrieved.
73
74       $format allows you to override format guessing.
75
76   XML::Feed->find_feeds($uri)
77       Given a URI $uri, use auto-discovery to find all of the feeds linked
78       from that page (using <link> tags).
79
80       Returns a list of feed URIs.
81
82   XML::Feed->identify_format(\$xml)
83       Given the xml of a feed return what format it is in, with "Atom" or
84       "RSS" for all versions of RSS.  Note that you pass in a scalar ref to
85       the xml string.
86
87   $feed->convert($format)
88       Converts the XML::Feed object into the $format format, and returns the
89       new object.
90
91   $feed->splice($other_feed)
92       Splices in all of the entries from the feed $other_feed into $feed,
93       skipping posts that are already in $feed.
94
95   $feed->format
96       Returns the format of the feed ("Atom", or some version of "RSS").
97
98   $feed->title([ $title ])
99       The title of the feed/channel.
100
101   $feed->base([ $base ])
102       The url base of the feed/channel.
103
104   $feed->link([ $uri ])
105       The permalink of the feed/channel.
106
107   $feed->tagline([ $tagline ])
108       The description or tagline of the feed/channel.
109
110   $feed->description([ $description ])
111       Alias for $feed->tagline.
112
113   $feed->author([ $author ])
114       The author of the feed/channel.
115
116   $feed->language([ $language ])
117       The language of the feed.
118
119   $feed->copyright([ $copyright ])
120       The copyright notice of the feed.
121
122   $feed->modified([ $modified ])
123       A DateTime object representing the last-modified date of the feed.
124
125       If present, $modified should be a DateTime object.
126
127   $feed->generator([ $generator ])
128       The generator of the feed.
129
130   $feed->self_link ([ $uri ])
131       The Atom Self-link of the feed:
132
133       <http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
134
135       A string.
136
137   $feed->entries
138       A list of the entries/items in the feed. Returns an array containing
139       XML::Feed::Entry objects.
140
141   $feed->items
142       A synonym (alias) for <$feed->entries>.
143
144   $feed->add_entry($entry)
145       Adds an entry to the feed. $entry should be an XML::Feed::Entry object
146       in the correct format for the feed.
147
148   $feed->as_xml
149       Returns an XML representation of the feed, in the format determined by
150       the current format of the $feed object.
151
152   $feed->first_link ([ $uri ])
153       The Atom First-link for feed paging and archiving (RFC 5005).
154
155       <http://tools.ietf.org/html/rfc5005>
156
157   $feed->last_link ([ $uri ])
158       The Atom Last-link for feed paging and archiving.
159
160   $feed->next_link ([ $uri ])
161       The Atom Next-link for feed paging and archiving.
162
163   $feed->previous_link ([ $uri ])
164       The Atom Previous-link for feed paging and archiving.
165
166   $feed->current_link ([ $uri ])
167       The Atom Current-link for feed paging and archiving.
168
169   $feed->next_archive_link ([ $uri ])
170       The Atom Next-link for feed paging and archiving.
171
172   $feed->prev_archive_link ([ $uri ])
173       The Atom Prev-Archive-link for feed paging and archiving.
174

PACKAGE VARIABLES

176       $XML::Feed::Format::RSS::PREFERRED_PARSER
177           If you want to use another RSS parser class than XML::RSS
178           (default), you can change the class by setting $PREFERRED_PARSER
179           variable in the XML::Feed::Format::RSS package.
180
181               $XML::Feed::Format::RSS::PREFERRED_PARSER = "XML::RSS::LibXML";
182
183           Note: this will only work for parsing feeds, not creating feeds.
184
185           Note: Only "XML::RSS::LibXML" version 0.3004 is known to work at
186           the moment.
187
188       $XML::Feed::MULTIPLE_ENCLOSURES
189           Although the RSS specification states that there can be at most one
190           enclosure per item some feeds break this rule.
191
192           If this variable is set then "XML::Feed" captures all of them and
193           makes them available as a list.
194
195           Otherwise it returns the last enclosure parsed.
196
197           Note: "XML::RSS" version 1.44 is needed for this to work.
198

VALID FEEDS

200       For reference, this cgi script will create valid, albeit nonsensical
201       feeds (according to "http://feedvalidator.org" anyway) for Atom 1.0 and
202       RSS 0.90, 0.91, 1.0 and 2.0.
203
204           #!perl -w
205
206           use strict;
207           use CGI;
208           use CGI::Carp qw(fatalsToBrowser);
209           use DateTime;
210           use XML::Feed;
211
212           my $cgi  = CGI->new;
213           my @args = ( $cgi->param('format') || "Atom" );
214           push @args, ( version => $cgi->param('version') ) if $cgi->param('version');
215
216           my $feed = XML::Feed->new(@args);
217           $feed->id("http://".time.rand()."/");
218           $feed->title('Test Feed');
219           $feed->link($cgi->url);
220           $feed->self_link($cgi->url( -query => 1, -full => 1, -rewrite => 1) );
221           $feed->modified(DateTime->now);
222
223           my $entry = XML::Feed::Entry->new();
224           $entry->id("http://".time.rand()."/");
225           $entry->link("http://example.com");
226           $entry->title("Test entry");
227           $entry->summary("Test summary");
228           $entry->content("Foo");
229           $entry->modified(DateTime->now);
230           $entry->author('test@example.com (Testy McTesterson)');
231           $feed->add_entry($entry);
232
233           my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "application/rss+xml";
234           print $cgi->header($mime);
235           print $feed->as_xml;
236

LICENSE

238       XML::Feed is free software; you may redistribute it and/or modify it
239       under the same terms as Perl itself.
240
242       Except where otherwise noted, XML::Feed is Copyright 2004-2008 Six
243       Apart. All rights reserved.
244

SUPPORT

246       For support contact the XML::Feed mailing list -
247       xml-feed@perlhacks.com.
248

SOURCE CODE

250       The latest version of XML::Feed can be found at
251
252           http://github.com/davorg/XML-Feed
253
254
255
256perl v5.28.0                      2015-12-14                      XML::Feed(3)
Impressum