XML::RSS::LibXML (3)
Leading comments
Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) Standard preamble: ========================================================================
NAME
XML::RSS::LibXML - XML::RSS with XML::LibXMLSYNOPSIS
use XML::RSS::LibXML; my $rss = XML::RSS::LibXML->new; $rss->parsefile($file); print "channel: $rss->{channel}->{title}\n"; foreach my $item (@{ $rss->{items} }) { print " item: $item->{title} ($item->{link})\n"; } # Add custom modules $rss->add_module(uri => $uri, prefix => $prefix); # See docs for XML::RSS for these $rss->channel(...); $rss->add_item(...); $rss->image(...); $rss->textinput(...); $rss->save(...); $rss->as_string($format); # XML::RSS::LibXML only methods my $version = $rss->version; my $base = $rss->base; my $hash = $rss->namespaces; my $list = $rss->items; my $encoding = $rss->encoding; my $modules = $rss->modules; my $output = $rss->output; my $stylesheets = $rss->stylesheets; my $num_items = $rss->num_items;
DESCRIPTION
XML::RSS::LibXML uses XML::LibXML (libxml2) for parsing
Use this module when you have severe performance requirements working with
VERSION 0.3105
The originalNow XML::RSS::LibXML is *almost* compatible with
COMPATIBILITY
There seems to be a bit of confusion as to how compatible XML::RSS::LibXML is withOn top of that, I originally wrote XML::RSS::LibXML as sort of a fast replacement for
From now on XML::RSS::LibXML will try to match
PARSED STRUCTURE
Once parsed the resulting data structure resembles that ofFor example, suppose you have a tag like the following:
<rss version="2.0" xml:base="http://example.com/"> ... <channel> <tag attr1="val1" attr2="val3">foo bar baz</tag> </channel> </rss>
All of the fields in this construct can be accessed like so:
$rss->channel->{tag} # "foo bar baz" $rss->channel->{tag}{attr1} # "val1" $rss->channel->{tag}{attr2} # "val2"
See XML::RSS::LibXML::MagicElement for details.
METHODS
new(%args)
Creates a new instance of XML::RSS::LibXML. You may specify a version or an
XML::RSS::LibXML->new(version => '1.0', base => 'http://example.com/');
The
XML::RSS::LiBXML->new(encoding => 'euc-jp');
parse($string)
Parse a string containingparsefile($filename)
Parse anchannel(%args)
add_item(%args)
image(%args)
textinput(%args)
These methods are used to generateAdditionally, add_item takes an extra parameter, ``mode'', which allows you to add items either in front of the list or at the end of the list:
$rss->add_item( mode => "append", title => "...", link => "...", ); $rss->add_item( mode => "insert", title => "...", link => "...", );
By default, items are appended to the end of the list
as_string($format)
Return the string representation of the parsedBy default, $format is true.
add_module(uri => $uri, prefix => $prefix)
Adds a new module. You should do this before parsing the
rdf => "www.w3.org/1999/02/22-rdf-syntax-ns#", dc => "purl.org/dc/elements/1.1", syn => "purl.org/rss/1.0/modules/syndication", admin => "webns.net/mvcb", content => "purl.org/rss/1.0/modules/content", cc => "web.resource.org/cc", taxo => "purl.org/rss/1.0/modules/taxonomy",
So you do not need to add these explicitly.
save($file)
Saves theitems()
Syntactic sugar to allow statement like this:
foreach my $item ($rss->items) { ... }
Instead of
foreach my $item (@{$rss->{items}}) { ... }
In scalar context, returns the reference to the list of items.
create_libxml()
Creates, configures, and returns an XML::LibXML object. Used by "parse()" to instantiate the parser used to parse the feed.PERFORMANCE
Here's a simple benchmark using benchmark.pl in this distribution, using
daisuke@beefcake XML-RSS-LibXML$ perl -Mblib tools/benchmark.pl t/data/rss20.xml XML::RSS -> 1.29_02 XML::RSS::LibXML -> 0.30 Rate rss rss_libxml rss 25.6/s -- -67% rss_libxml 78.1/s 205% --
CAVEATS
- Only first level data under <channel> and <item> tags are examined. So if you have complex data, this module will not pick it up. For most of the cases, this will suffice, though.- Namespace for namespaced attributes aren't properly parsed as part of the structure. Hopefully your
<foo bar:baz="whee">
You won't be able to get at ``bar'' in this case:
$xml->{foo}{baz}; # "whee" $xml->{foo}{bar}{baz}; # nope
- Some of the structures will need to be handled via XML::RSS::LibXML::MagicElement. For example,
$rss->add_item(title => "GTKeyboard 0.85", # creates a guid field with permaLink=true permaLink => "freshmeat.net/news/1999/06/21/930003829.html", # alternately creates a guid field with permaLink=false # guid => "gtkeyboard-0.85 enclosure => { url=> 'http://example.com/torrent', type=>"application/x-bittorrent" }, description => 'blah blah' );
However, the enclosure element will need to be an object:
enclosure => XML::RSS::LibXML::MagicElement->new( attributes => { url => 'http://example.com/torrent', type=>"application/x-bittorrent" }, );
- Some elements such as permaLink elements are not really parsed such that it can be serialized and parsed back and force. I could fix this, but that would break some compatibility with
TODO
Tests. Currently tests are simply stolen fromSEE ALSO
COPYRIGHT AND LICENSE
Copyright (c) 2005-2007 Daisuke Maki <dmaki@cpan.org>, Tatsuhiko Miyagawa <miyagawa@bulknews.net>. All rights reserved.Many tests were shamelessly borrowed from
Development partially funded by Brazil, Ltd. <b.razil.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.