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. $stream can be any one
56       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 ("Atom", or some
84       version of "RSS").
85
86   $feed->convert($format)
87       Converts the XML::Feed object into the $format format, and returns the
88       new object.
89
90   $feed->splice($other_feed)
91       Splices in all of the entries from the feed $other_feed into $feed,
92       skipping posts that are already in $feed.
93
94   $feed->format
95       Returns the format of the feed ("Atom", or some version of "RSS").
96
97   $feed->title([ $title ])
98       The title of the feed/channel.
99
100   $feed->base([ $base ])
101       The url base of the feed/channel.
102
103   $feed->link([ $uri ])
104       The permalink of the feed/channel.
105
106   $feed->tagline([ $tagline ])
107       The description or tagline of the feed/channel.
108
109   $feed->description([ $description ])
110       Alias for $feed->tagline.
111
112   $feed->author([ $author ])
113       The author of the feed/channel.
114
115   $feed->language([ $language ])
116       The language of the feed.
117
118   $feed->copyright([ $copyright ])
119       The copyright notice of the feed.
120
121   $feed->modified([ $modified ])
122       A DateTime object representing the last-modified date of the feed.
123
124       If present, $modified should be a DateTime object.
125
126   $feed->generator([ $generator ])
127       The generator of the feed.
128
129   $feed->self_link ([ $uri ])
130       The Atom Self-link of the feed:
131
132       <http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
133
134       A string.
135
136   $feed->entries
137       A list of the entries/items in the feed. Returns an array containing
138       XML::Feed::Entry objects.
139
140   $feed->items
141       A synonym for $feed-entries>.
142
143   $feed->add_entry($entry)
144       Adds an entry to the feed. $entry should be an XML::Feed::Entry object
145       in the correct format for the feed.
146
147   $feed->as_xml
148       Returns an XML representation of the feed, in the format determined by
149       the current format of the $feed object.
150

PACKAGE VARIABLES

152       $XML::Feed::RSS::PREFERRED_PARSER
153           If you want to use another RSS parser class than XML::RSS
154           (default), you can change the class by setting $PREFERRED_PARSER
155           variable in XML::Feed::RSS package.
156
157               $XML::Feed::RSS::PREFERRED_PARSER = "XML::RSS::LibXML";
158
159           Note: this will only work for parsing feeds, not creating feeds.
160
161           Note: Only "XML::RSS::LibXML" version 0.3004 is known to work at
162           the moment.
163
164       $XML::Feed::MULTIPLE_ENCLOSURES
165           Although the RSS specification states that there can be at most one
166           enclosure per item some feeds break this rule.
167
168           If this variable is set then "XML::Feed" captures all of them and
169           makes them available as a list.
170
171           Otherwise it returns the last enclosure parsed.
172
173           Note: "XML::RSS" version 1.44 is needed for this to work.
174

VALID FEEDS

176       For reference, this cgi script will create valid, albeit nonsensical
177       feeds (according to "http://feedvalidator.org" anyway) for Atom 1.0 and
178       RSS 0.90, 0.91, 1.0 and 2.0.
179
180           #!perl -w
181
182           use strict;
183           use CGI;
184           use CGI::Carp qw(fatalsToBrowser);
185           use DateTime;
186           use XML::Feed;
187
188           my $cgi  = CGI->new;
189           my @args = ( $cgi->param('format') || "Atom" );
190           push @args, ( version => $cgi->param('version') ) if $cgi->param('version');
191
192           my $feed = XML::Feed->new(@args);
193           $feed->id("http://".time.rand()."/");
194           $feed->title('Test Feed');
195           $feed->link($cgi->url);
196           $feed->self_link($cgi->url( -query => 1, -full => 1, -rewrite => 1) );
197           $feed->modified(DateTime->now);
198
199           my $entry = XML::Feed::Entry->new();
200           $entry->id("http://".time.rand()."/");
201           $entry->link("http://example.com");
202           $entry->title("Test entry");
203           $entry->summary("Test summary");
204           $entry->content("Foo");
205           $entry->modified(DateTime->now);
206           $entry->author('test@example.com (Testy McTesterson)');
207           $feed->add_entry($entry);
208
209           my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "application/rss+xml";
210           print $cgi->header($mime);
211           print $feed->as_xml;
212

LICENSE

214       XML::Feed is free software; you may redistribute it and/or modify it
215       under the same terms as Perl itself.
216
218       Except where otherwise noted, XML::Feed is Copyright 2004-2008 Six
219       Apart, cpan@sixapart.com. All rights reserved.
220

SUBVERSION

222       The latest version of XML::Feed can be found at
223
224           http://code.sixapart.com/svn/XML-Feed/trunk/
225
226
227
228perl v5.12.0                      2009-05-07                      XML::Feed(3)
Impressum