XML::Filter::XML_Directory_2RSS - SAX2 filter for generating RSS from the output of XML::Directory::SAX
use IO::File; use XML::SAX::Writer; use XML::Directory::SAX; use XML::Filter::XML_Directory_2RSS; my $rss = "/path/to/rss.xml"; my $directory = "/path/to/some/directory"; # my $output = IO::File->new(">$rss"); my $writer = XML::SAX::Writer->new(Output=>$output); my $filter = XML::Filter::XML_Directory_2RSS->new(Handler=>$writer); # Various RSS meta data methods $rss->uri("http://www.foo.com/rss.xml"); $rss->channel_data({title => "foo", link => "http://foo.com", subject => "bar", descripion => "foo is to bar as bar is to foo"}); $rss->generator($0); # Set up one or more events for affecting the # data describe in your RSS document $rss->callbacks({link => \&do_link}); $rss->handlers({title=>MySax::Title->new(Handler=>$writer)}); # Describe items to be explicily excluded (or included) # in your RSS document. $rss->exclude(exclude=>["RCS","CVS"],ending=>["~"]); # Parse parse parse my $directory = XML::Directory::SAX->new(Handler => $filter, detail => 2, depth => 1); $directory->order_by("a"); $directory->parse_dir($directory); # sub do_link { my $link = shift; $link =~ s!$directory!http://www.foo.com!s; return $link; }
SAX2 filter for generating RSS from the output of XML::Directory::SAX.
This package has very limited support for RSS modules. I'm workin' on it.
Set the encoding type for your RSS document. Default is UTF-8
Set the URI for your RSS document. This is the value of the channel@rdf:about attribute.
Set channel data for your RSS document.
Valid arguments are :
title
String.
link
subject
description
dc:rights
dc:publisher
dc:creator
dc:language
Array reference.
Proper support for RSS 1.0 modules is in the works.
Set image data for your RSS document.
url
Set textinput data for your RSS document.
name
Set generator agent data for your RSS document.
Currently this is really only used by the Syndic8 project, but it's a good idea so we'll add hooks it for.
This method is inherited from XML::Filter::XML_Directory_Pruner. See docs for details.
A is a valid SAX2 thingy for assigning the title or description element of an RSS item. Thingies are like any other SAX2 thingy with a few requirements :
Must inherit from XML::SAX::Base.
It's handler must be the same one passed to the XML_Directory_2RSS filter.
It must define a parse_uri method.
# If this... my $writer = XML::SAX::Writer->new(); my $rss = XML::Filter::XML_Directory_2RSS->new(Handler=>$writer); $rss->handler({title=>MySAX::TitleHandler->new(Handler=>$writer)}); # Called this... package MySAX::TitleHandler; use base qw (XML::SAX::Base); sub parse_uri { my ($pkg,$path,$title) = @_; $pkg->SUPER::start_prefix_mapping({Prefix=>"me",NamespaceURI=>"..."}); $pkg->SUPER::start_element({Name=>"me:woot"}); $pkg->SUPER::characters({Data=>&get_title_from_file($path)}); $pkg->SUPER::end_element({Name=>"me:woot"}); $pkg->SUPER::end_prefix_mapping({Prefix=>"me"}); } # Then the output would look like this... <item> <title> <me:woot xmlns:me="...">I Got My Title From the File</me:woot> </title> <link>...</link> <description /> </item>
Object.
The handler's parse_uri method is passed the absolute path of the file and the filename itself.
If no handler, or callback, is defined then the filename will be assigned to the title element.
The handler's parse_uri method is passed the absolute path of the file.
If no handler, or callback, is defined then the description element will be left empty.
Handlers have a higher precedence than callbacks.
Register one of more callbacks for your RSS document.
Callbacks are like handlers except that they are code references instead of SAX2 thingies.
A code reference might be used to munge the link value of an item into a URI suitable for viewing in a web browser.
Valid arguments are
Code reference.
Code references will be passed the absolute path of the file and the filename itself.
If no callback, or handler, is defined then the filename will be assigned to the title element.
Code references will be passed the absolute path of the file.
If no callback is defined then the absolute path of the file will be assigned to the link element.
If no callback, or handler, the descripion element will be left empty.
Callbacks have a lower precedence than handlers.
0.9.1
May 24, 2002
Aaron Straup Cope
Proper support for RSS modules.
XML::Filter::XML_Directory::Pruner
XML::Directory::SAX
http://groups.yahoo.com/group/rss-dev/files/specification.html
Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.
This is free software, you may use it and distribute it under the same terms as Perl itself.
To install XML::Filter::XML_Directory_2RSS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Filter::XML_Directory_2RSS
CPAN shell
perl -MCPAN -e shell install XML::Filter::XML_Directory_2RSS
For more information on module installation, please visit the detailed CPAN module installation guide.