NAME

XML::RSS::Parser - A liberal object-oriented parser for RSS feeds.

SYNOPSIS

#!/usr/bin/perl -w

use strict;
use XML::RSS::Parser;

my $p = new XML::RSS::Parser;
my $feed = $p->parsefile('/path/to/some/rss/file');
	
# output some values
my $title = XML::RSS::Parser->ns_qualify('title',$feed->rss_namespace_uri);
print $feed->channel->children($title)->value."\n";
print "item count: ".$feed->item_count()."\n\n";
foreach my $i ( $feed->items ) {
	map { print $_->name.": ".$_->value."\n" } $i->children;
	print "\n";
} 

DESCRIPTION

XML::RSS::Parser is a lightweight liberal parser of RSS feeds that is derived from the XML::Parser::LP module the I developed for mt-rssfeed -- a Movable Type plugin. This parser is "liberal" in that it does not demand compliance of a specific RSS version and will attempt to gracefully handle tags it does not expect or understand. The parser's only requirements is that the file is well-formed XML and remotely resembles RSS.

There are a number of advantages to using this module then just using a standard parser-tree combination. There are a number of different RSS formats in use today. In very subtle ways these formats are not entirely compatible from one to another. XML::RSS::Parser makes a few assumptions to "normalize" the parse tree into a more consistent form. For instance, it forces channel and item into a parent-child relationship and locates one (if any) of the known RSS Namespace URIs and maps them into a common form. For more detail see "SPECIAL PROCESSING NOTES".

This module is leaner then XML::RSS -- the majority of code was for generating RSS files. It also provides a XPath-esque interface to the feed's tree.

While XML::RSS::Parser creates a normalized parse tree, it still leaves the mapping of overlapping and alternate tags common in the RSS format space to the developer. For this look at the XML::RAI (RSS Abstraction Interface) package which provides an object-oriented layer to XML::RSS::Parser trees that transparently maps these various tags to one common interface.

Your feedback and suggestions are greatly appreciated. See the "TO DO" section for some brief thoughts on next steps.

SPECIAL PROCESSING NOTES

There are a number of different RSS formats in use today. In very subtle ways these formats are not entirely compatible from one to another. What's worse is that there are unlabeled versions within the standard in addition to tags with overlapping purposes and vague definitions. (See Mark Pilgrim's "The myth of RSS compatibility" http://diveintomark.org/archives/2004/02/04/incompatible-rss for just a sampling of what I mean.) To ease working with RSS data in different formats, the parser does not create the feed's parse tree verbatim. Instead it makes a few assumptions to "normalize" the parse tree into a more consistent form.

  • The parser will not include the root tags of rss or RDF in the tree. Namespace declaration information is still extracted.

  • The parser forces channel and item into a parent-child relationship. In versions 0.9 and 1.0, channel and item tags are siblings.

  • Rather then creating character nodes for each tag element, the parser stores the tags contents as the nodes value in most cases. These instances include direct descendants of item and image in addition to direct descedents of channel not mentioned.

  • Some more advanced feeds in existence take advantage of namespace extensions that are permitted by RSS 1.0 and 2.0 (note: the versions are not related) and embed complex blocks markup from other grammars. The parser can pass through these blocks as a single node and stores the unparsed markup in the tree for ease of handling and later parsing. Two common instances in feeds that are currently supported are XHTML bodies and FOAF persons.

    An XHTML body can be retrieved by the element name of http://www.w3.org/1999/xhtml/body.
    A FOAF person can be retrieved by the element name of http://xmlns.com/foaf/0.1/person. Some feeds that were found use Person (capital P) -- the parser will pass-thru those blocks but you have to retrieve the node with the slightly different name.

METHODS

The following objects and methods are provided in this package.

XML::RSS::Parser->new

Constructor. Returns a reference to a new XML::RSS::Parser object.

$parser->parse(source)

Inherited from XML::Parser, the SOURCE parameter should either open an IO::Handle or a string containing the whole XML document. A die call is thrown if a parse error occurs otherwise it will return a XML::RSS::Parser::Feed object.

$parser->parsefile(file)

Inherited from XML::Parser, FILE is an open handle. The file is closed no matter how parse returns. A die call is thrown if a parse error occurs otherwise it will return a XML::RSS::Parser::Feed object.

XML::RSS::Parser->ns_qualify(element, namesapce_uri)

An simple utility method implemented as an abstract method that will return a fully namespace qualified string for the supplied element.

DEPENDENCIES

XML::Parser

SEE ALSO

XML::RSS::Parser::Element, XML::RSS::Parser::Feed, XML::Parser, XML::RAI

The Feed Validator http://www.feedvalidator.org/

What is RSS? http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html

Raising the Bar on RSS Feed Quality "/www.oreillynet.com/pub/a/webservices/2002/11/19/ rssfeedquality.html" in http:

The myth of RSS compatibility http://diveintomark.org/archives/2004/02/04/incompatible-rss

TO DO

  • Add whitespace filtering switch.

  • Add methods for adding more namespaces/blocks to pass-thru or to pass to a handler routine.

LICENSE

The software is released under the Artistic License. The terms of the Artistic License are described at http://www.perl.com/language/misc/Artistic.html.

AUTHOR & COPYRIGHT

Except where otherwise noted, XML::RSS::Parser is Copyright 2003-2004, Timothy Appnel, cpan@timaoutloud.org. All rights reserved.

5 POD Errors

The following errors were encountered while parsing the POD:

Around line 169:

=begin without a target?

Around line 278:

You forgot a '=back' before '=head1'

Around line 282:

'=item' outside of any '=over'

Around line 306:

You forgot a '=back' before '=head1'

Around line 352:

'=end' without a target?