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->get_file($filename)
77       Gets a feed from a file.
78
79       CML::Feed->get_fh($fh)
80
81       Gets a feed from pre-opened filehandle.
82
83   XML::Feed->get_uri($uri)
84       Gets a feed from a URI.
85
86   XML::Feed->find_feeds($uri)
87       Given a URI $uri, use auto-discovery to find all of the feeds linked
88       from that page (using <link> tags).
89
90       Returns a list of feed URIs.
91
92   XML::Feed->identify_format(\$xml)
93       Given the xml of a feed return what format it is in, with "Atom" or
94       "RSS" for all versions of RSS.  Note that you pass in a scalar ref to
95       the xml string.
96
97   $feed->convert($format)
98       Converts the XML::Feed object into the $format format, and returns the
99       new object.
100
101   $feed->splice($other_feed)
102       Splices in all of the entries from the feed $other_feed into $feed,
103       skipping posts that are already in $feed.
104
105   $feed->format
106       Returns the format of the feed ("Atom", or some version of "RSS").
107
108   $feed->title([ $title ])
109       The title of the feed/channel.
110
111   $feed->base([ $base ])
112       The url base of the feed/channel.
113
114   $feed->link([ $uri ])
115       The permalink of the feed/channel.
116
117   $feed->tagline([ $tagline ])
118       The description or tagline of the feed/channel.
119
120   $feed->description([ $description ])
121       Alias for $feed->tagline.
122
123   $feed->author([ $author ])
124       The author of the feed/channel.
125
126   $feed->language([ $language ])
127       The language of the feed.
128
129   $feed->copyright([ $copyright ])
130       The copyright notice of the feed.
131
132   $feed->modified([ $modified ])
133       A DateTime object representing the last-modified date of the feed.
134
135       If present, $modified should be a DateTime object.
136
137   $feed->generator([ $generator ])
138       The generator of the feed.
139
140   $feed->self_link ([ $uri ])
141       The Atom Self-link of the feed:
142
143       <http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
144
145       A string.
146
147   $feed->entries
148       A list of the entries/items in the feed. Returns an array containing
149       XML::Feed::Entry objects.
150
151   $feed->items
152       A synonym (alias) for "$feed->entries".
153
154   $feed->add_entry($entry)
155       Adds an entry to the feed. $entry should be an XML::Feed::Entry object
156       in the correct format for the feed.
157
158   $feed->as_xml
159       Returns an XML representation of the feed, in the format determined by
160       the current format of the $feed object.
161
162   $feed->first_link ([ $uri ])
163       The Atom First-link for feed paging and archiving (RFC 5005).
164
165       <http://tools.ietf.org/html/rfc5005>
166
167   $feed->last_link ([ $uri ])
168       The Atom Last-link for feed paging and archiving.
169
170   $feed->next_link ([ $uri ])
171       The Atom Next-link for feed paging and archiving.
172
173   $feed->previous_link ([ $uri ])
174       The Atom Previous-link for feed paging and archiving.
175
176   $feed->current_link ([ $uri ])
177       The Atom Current-link for feed paging and archiving.
178
179   $feed->next_archive_link ([ $uri ])
180       The Atom Next-link for feed paging and archiving.
181
182   $feed->prev_archive_link ([ $uri ])
183       The Atom Prev-Archive-link for feed paging and archiving.
184

PACKAGE VARIABLES

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

VALID FEEDS

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

LICENSE

248       XML::Feed is free software; you may redistribute it and/or modify it
249       under the same terms as Perl itself.
250
252       Except where otherwise noted, XML::Feed is Copyright 2004-2008 Six
253       Apart. All rights reserved.
254

SUPPORT

256       For support contact the XML::Feed mailing list -
257       xml-feed@perlhacks.com.
258

SOURCE CODE

260       The latest version of XML::Feed can be found at
261
262           http://github.com/davorg/XML-Feed
263
264
265
266perl v5.34.0                      2021-07-27                      XML::Feed(3)
Impressum