XML::Feed(3pm)

๐Ÿ’– XML::Feed(3pm) โ€” the manual page, but make it cute ๐Ÿ’–

okay bestie, pull up a chair, we're reading a man page together and honestly? it's a good one. this is <purple>XML::Feed(3pm)</purple> from the User Contributed Perl Documentation crew, and it's about to be your new hyperfixation. no cap. ๐Ÿฆ‹


โœจ NAME โœจ

XML::Feed โ€” syndication feed parser and auto-discovery. it literally does both. main character energy fr. ๐Ÿ‘‘


๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

bestie here's the vibe in code form, copy it exactly, don't retype it from memory:

use XML::Feed;
my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml'))
    or die XML::Feed->errstr;
print $feed->title, "\n";
for my $entry ($feed->entries) {
}

## Find all of the syndication feeds on a given page, using
## auto-discovery.
my @feeds = XML::Feed->find_feeds('http://example.com/');

look at that. clean. slay. ๐Ÿ’…


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

XML::Feed is a syndication feed parser for both RSS and Atom feeds. it also implements feed auto-discovery for finding feeds, given a URI. it's giving two jobs and doing both flawlessly, honestly iconic. โœจ

here's the format roster it fucks with (affectionate):

  • RSS 0.91
  • RSS 1.0
  • RSS 2.0
  • Atom

the whole goal of XML::Feed is to give you one unified API for parsing and using all these different syndication formats. because babes โ€” the different flavors of RSS and Atom handle data in completely different ways: date handling, summaries and content, escaping and quoting, etc. etc. etc. ๐Ÿ˜ญ

this module tries to remove those differences by wrapping the formats and the classes that implement them (XML::RSS and XML::Atom::Feed). for example! dates are handled differently in each of the formats above. so to give you a unified API for date handling, XML::Feed converts all date formats transparently into DateTime objects, which it then hands back to the caller. it's giving translator bestie, we love a middleman who actually helps. ๐Ÿซถ


๐ŸŒธ USAGE ๐ŸŒธ

๐Ÿงš XML::Feed->new($format)

๐Ÿงš XML::Feed->new($format, \%args)

creates a new empty XML::Feed object using the format $format. look:

$feed = XML::Feed->new('Atom');
$feed = XML::Feed->new('RSS');
$feed = XML::Feed->new('RSS', version => '0.91');

an optional hashref of arguments can be provided as the last parameter:

my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed = XML::Feed->new('Atom', { useragent => $ua });

currently supported arguments, bestie, listen up:

  • useragent โ€” an LWP::UserAgent object (or subclass) to use for fetching feeds via URI. if you don't provide one, a default UserAgent will be created when needed. it's got a whole backup plan, we stan a prepared queen. ๐Ÿ’…

๐ŸŒŸ XML::Feed->parse($stream)

๐ŸŒŸ XML::Feed->parse($stream, \%args)

๐ŸŒŸ XML::Feed->parse($stream, $format)

๐ŸŒŸ XML::Feed->parse($stream, $format, \%args)

parses a syndication feed identified by $stream and returns an XML::Feed object. $stream can be any one of the following:

  • Scalar reference โ€” a reference to string containing the XML body of the feed.
  • Filehandle โ€” an open filehandle from which the feed XML will be read.
  • File name โ€” the name of a file containing the feed XML.
  • URI object โ€” a URI from which the feed XML will be retrieved.

$format lets you override format guessing. (yes, it guesses. it's psychic like that. ๐Ÿ”ฎ)

an optional hashref of arguments can be provided as the last parameter:

my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed = XML::Feed->parse('https://example.com/feed', { useragent => $ua });

currently supported arguments:

  • useragent โ€” an LWP::UserAgent object (or subclass) to use for fetching feeds via URI. if not provided, a default UserAgent will be created when needed. (same deal as before, she's consistent ๐Ÿ’–)

๐Ÿ’ซ XML::Feed->get_file($filename)

gets a feed from a file. simple! iconic!

๐Ÿ’ซ CML::Feed->get_fh($fh)

gets a feed from pre-opened filehandle.

ngl bestie, that CML::Feed is literally how it's written in the original manual page. i am not fixing it. i am not touching it. do not come for me, take it up with the manpage. ๐Ÿ’€

๐Ÿ’ซ XML::Feed->get_uri($uri)

gets a feed from a URI.

๐Ÿ”Ž XML::Feed->find_feeds($uri)

given a URI $uri, use auto-discovery to find all of the feeds linked from that page (using <link> tags).

returns a list of feed URIs. she's a detective and she found them all, periodt. ๐Ÿ•ต๏ธโ™€๏ธโœจ

๐Ÿ”Ž XML::Feed->identify_format(\$xml)

given the xml of a feed, return what format it is in, with "Atom" or "RSS" for all versions of RSS. note: you pass in a scalar ref to the xml string. don't forget the ref or she'll be confused and honestly same. ๐Ÿ™ˆ

๐Ÿ”„ $feed->convert($format)

converts the XML::Feed object into the $format format, and returns the new object.

๐Ÿ”„ $feed->splice($other_feed)

splices in all of the entries from the feed $other_feed into $feed, skipping posts that are already in $feed. no duplicates allowed, she has boundaries. ๐Ÿšซ๐Ÿ’–

๐Ÿท๏ธ $feed->format

returns the format of the feed ("Atom", or some version of "RSS").

๐Ÿท๏ธ $feed->title([ $title ])

the title of the feed/channel.

๐Ÿท๏ธ $feed->base([ $base ])

the url base of the feed/channel.

the permalink of the feed/channel.

๐Ÿท๏ธ $feed->tagline([ $tagline ])

the description or tagline of the feed/channel.

๐Ÿท๏ธ $feed->description([ $description ])

alias for $feed->tagline. (same girl, different name โœจ)

๐Ÿท๏ธ $feed->author([ $author ])

the author of the feed/channel.

๐Ÿท๏ธ $feed->language([ $language ])

the language of the feed.

the copyright notice of the feed. protect the intellectual property bestie ยฉ๏ธ

๐Ÿ• $feed->modified([ $modified ])

a DateTime object representing the last-modified date of the feed.

if present, $modified should be a DateTime object. not optional-optional, like, actually do this.

๐Ÿท๏ธ $feed->generator([ $generator ])

the generator of the feed.

the Atom Self-link of the feed:

<http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>

a string. that's it, that's the whole vibe.

๐Ÿ“š $feed->entries

a list of the entries/items in the feed. returns an array containing XML::Feed::Entry objects.

๐Ÿ“š $feed->items

a synonym (alias) for "$feed->entries". two names, one queen. ๐Ÿ‘‘

โž• $feed->add_entry($entry)

adds an entry to the feed. $entry should be an XML::Feed::Entry object in the correct format for the feed. format match or it's not vibing, iykyk.

๐Ÿ“ $feed->as_xml

returns an XML representation of the feed, in the format determined by the current format of the $feed object.

๐Ÿ•ต๏ธ $feed->useragent([ $ua ])

get or set the LWP::UserAgent object used for fetching feeds.

if called without arguments, returns the current UserAgent object, creating a default one if it doesn't exist. (she'll make one for you, she's generous like that.)

if called with an LWP::UserAgent object (or subclass), sets it as the UserAgent for this feed.

my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed->useragent($ua);

# Later, retrieve it
my $current_ua = $feed->useragent;

the Atom First-link for feed paging and archiving (RFC 5005).

<http://tools.ietf.org/html/rfc5005>

the Atom Last-link for feed paging and archiving.

the Atom Next-link for feed paging and archiving.

the Atom Previous-link for feed paging and archiving.

the Atom Current-link for feed paging and archiving.

the Atom Next-link for feed paging and archiving.

the Atom Prev-Archive-link for feed paging and archiving.


๐ŸŒˆ PACKAGE VARIABLES ๐ŸŒˆ

๐Ÿ’œ $XML::Feed::Format::RSS::PREFERRED_PARSER

if you want to use another RSS parser class than XML::RSS (the default), you can change the class by setting the $PREFERRED_PARSER variable in the XML::Feed::Format::RSS package.

$XML::Feed::Format::RSS::PREFERRED_PARSER = "XML::RSS::LibXML";
Note: this will only work for parsing feeds, not creating feeds. know the limits bestie ๐Ÿซถ
Note: only "XML::RSS::LibXML" version 0.3004 is known to work at the moment. specific queen, specific version. ๐Ÿ’…

๐Ÿ’œ $XML::Feed::MULTIPLE_ENCLOSURES

although the RSS specification states that there can be at most one enclosure per item, some feeds break this rule. rude of them honestly. ๐Ÿ˜ค

if this variable is set, then "XML::Feed" captures all of them and makes them available as a list.

otherwise, it returns the last enclosure parsed. (last one wins, bye to the rest ๐Ÿ‘‹)

Note: "XML::RSS" version 1.44 is needed for this to work. no version 1.44, no list, sorry bestie.

๐Ÿงช VALID FEEDS ๐Ÿงช

for reference, this cgi script will create valid, albeit nonsensical feeds (according to "http://feedvalidator.org" anyway) for Atom 1.0 and RSS 0.90, 0.91, 1.0 and 2.0. nonsensical but valid? that's the dream combo fr fr. ๐Ÿ”ฅ

#!perl -w

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DateTime;
use XML::Feed;

my $cgi  = CGI->new;
my @args = ( $cgi->param('format') // "Atom" );
push @args, ( version => $cgi->param('version') ) if $cgi->param('version');

my $feed = XML::Feed->new(@args);
$feed->id("http://".time.rand()."/");
$feed->title('Test Feed');
$feed->link($cgi->url);
$feed->self_link($cgi->url( -query => 1, -full => 1, -rewrite => 1) );
$feed->modified(DateTime->now);

my $entry = XML::Feed::Entry->new();
$entry->id("http://".time.rand()."/");
$entry->link("http://example.com");
$entry->title("Test entry");
$entry->summary("Test summary");
$entry->content("Foo");
$entry->modified(DateTime->now);
$entry->author('test@example.com (Testy McTesterson)');
$feed->add_entry($entry);

my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "application/rss+xml";
print $cgi->header($mime);
print $feed->as_xml;

๐Ÿ“œ LICENSE ๐Ÿ“œ

XML::Feed is free software; you may redistribute it and/or modify it under the same terms as Perl itself. free is free bestie, redistribute away. ๐Ÿ•Š๏ธ


except where otherwise noted, XML::Feed is Copyright 2004-2008 Six Apart. all rights reserved.


๐Ÿ†˜ SUPPORT ๐Ÿ†˜

for support, contact the XML::Feed mailing list โ€” xml-feed@perlhacks.com. they're your people now. email them. ๐Ÿซ‚


๐Ÿ’ป SOURCE CODE ๐Ÿ’ป

the latest version of XML::Feed can be found at

http://github.com/davorg/XML-Feed

go. clone it. star it. that's your homework. โญ


okay and that's the whole page bestie!! this was XML::Feed(3pm), documented under perl v5.40.1, dated 2026-02-21 โ€” like, the future. ๐Ÿ’ซ thanks for reading the whole thing with me, you ate that fr fr. now go parse a feed and slay ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

๐Ÿ“ฆ where this page comes from