Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the XML-RSS-LibXML CPAN distribution.

Report information
The Basics
Id: 16746
Status: new
Priority: 0/
Queue: XML-RSS-LibXML

People
Owner: Nobody in particular
Requestors: aar [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.14
Fixed in: (no value)



Subject: Support for multiple categories
Download (untitled) / with headers
text/plain 649b
Greetings, the RSS 2.0 specification allows multiple <category> tags inside <item>. XML::RSS::LibXML currently reads the first only. I'm sending you a little patch to handle multiple categories. The 'category' element in the hash will be a scalar (just like now) if there's one category only, otherwise it will be an arrayref with all the values inside. I chose to follow your liberal approach, so this behaviour will be adopted just for every multiple element that may occur into the <item> tag being parsed. I strongly invite you to merge this patch in order to better comply with the RSS 2.0 specs. Cheers, Alessandro Ranellucci aar@cpan.org
Download multiple.patch
text/x-diff 1.9k
--- XML-RSS-LibXML-0.14.1/lib/XML/RSS/LibXML/Parser.pm Sun Nov 20 13:09:09 2005 +++ XML-RSS-LibXML-0.14/lib/XML/RSS/LibXML/Parser.pm Tue Dec 27 15:40:47 2005 @@ -221,11 +221,12 @@ # now, for each node that we can cover, go and parse foreach my $node ($xc->findnodes($xpath, $root)) { + my $val; if ($xc->findnodes('./*', $node)) { -# print STDERR "Parsing ", $node->getName(), " (recurse)\n"; - $sub{$node->localname} = $self->_parse_children($version, $node); + # print STDERR "Parsing ", $node->getName(), " (recurse)\n"; + $val = $self->_parse_children($version, $node); } else { -# print STDERR "Parsing ", $node->getName(), "\n"; + # print STDERR "Parsing ", $node->getName(), "\n"; my $text = $node->textContent(); if ($text !~ /\S/) { $text = ''; @@ -233,14 +234,24 @@ # argh. it has attributes. we do our little hack... if ($node->hasAttributes) { - $sub{$node->localname} = XML::RSS::LibXML::MagicElement->new( + $val = XML::RSS::LibXML::MagicElement->new( content => $text, attributes => [ $node->attributes ] ); } else { - $sub{$node->localname} = $text; + $val = $text; } } + + # multiple values for the same key will + # be stored as an arrayref instead of a scalar + if (!defined $sub{$node->localname}) { + $sub{$node->localname} = $val; + } elsif (ref $sub{$node->localname} eq 'ARRAY') { + push @{ $sub{$node->localname} }, $val; + } else { + $sub{$node->localname} = [ $sub{$node->localname}, $val ]; + } } if (keys %sub) {


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.