Skip Menu |
 

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

Report information
The Basics
Id: 12055
Status: rejected
Worked: 15 min
Priority: 0/
Queue: XML-RSS

People
Owner: SHLOMIF [...] cpan.org
Requestors: orion [...] mediarights.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.05
Fixed in: (no value)

Attachments


Subject: Patch to create RDF:Bag elements when passed array references
Download (untitled) / with headers
text/plain 1.1k
We had a number of cases where we wanted to keep RDF data in Bag elements, but XML::RSS didn't support this, and if we tried to pass them as thing => " <RDF:Bag> <RDF:li>foo</RDF:li> <RDF:li>bar</RDF:li> </RDF:Bag>", everything got escaped, as it should, but that was not what we wanted. So this patch changes the encode subroutine such that if you pass it an array reference, you get a <$prefix:Bag> element with the contents of the array. E.g., if we have an array @categories with a number of categories for a news item, we add the item like so: $rss->add_item( title => "patch to create RDF:Bag elements when passed array references", link => "http://rt.cpan.org", description => "patch", mrNews => { categories => \@categories, } ); And this would output: <mrNews:categories> <mrNews:Bag> <mrNews:li>foo</mrNews:li> <mrNews:li>bar</mrNews:li> </mrNews:Bag> </mrNews:categories> I suppose the optimal behavior would be to put arrays in <$prefix:Seq> and put hashes or lists in <$prefix:Bag>, but I just thought of that now, and it's not something I need.
Download XML-RSS_bag.patch
text/x-diff 3.2k
--- RSS-bag.pm 2005-03-29 12:37:19.000000000 -0500 +++ XML-RSS-1.05/lib/RSS.pm 2005-03-29 11:05:28.000000000 -0500 @@ -6,7 +6,7 @@ use XML::Parser; use vars qw($VERSION $AUTOLOAD @ISA $modules $AUTO_ADD); -$VERSION = '1.05-bag'; +$VERSION = '1.05'; @ISA = qw(XML::Parser); $AUTO_ADD = 0; @@ -906,7 +906,7 @@ qq!" />\n!; } else { - $output .= "<$prefix:$el>". $self->encode($value,$prefix) ."</$prefix:$el>\n"; + $output .= "<$prefix:$el>". $self->encode($value) ."</$prefix:$el>\n"; } } } @@ -976,7 +976,7 @@ qq!" />\n!; } else { - $output .= "<$prefix:$el>". $self->encode($value,$prefix) ."</$prefix:$el>\n"; + $output .= "<$prefix:$el>". $self->encode($value) ."</$prefix:$el>\n"; } } } @@ -1022,7 +1022,7 @@ qq!" />\n!; } else { - $output .= "<$prefix:$el>". $self->encode($value,$prefix) ."</$prefix:$el>\n"; + $output .= "<$prefix:$el>". $self->encode($value) ."</$prefix:$el>\n"; } } } @@ -1051,7 +1051,7 @@ while ( my($url, $prefix) = each %{$self->{modules}} ) { next if $prefix =~ /^(dc|syn|taxo)$/; while ( my($el, $value) = each %{$self->{textinput}->{$prefix}} ) { - $output .= "<$prefix:$el>". $self->encode($value,$prefix) ."</$prefix:$el>\n"; + $output .= "<$prefix:$el>". $self->encode($value) ."</$prefix:$el>\n"; } } @@ -1781,31 +1781,17 @@ my $entities = join('|', keys %entity); sub encode { - my ($self, $text, $prefix) = @_; - return $text unless $self->{'encode_output'}; - - my $encoded_text = ''; - if (ref $text eq 'ARRAY') { - if(!$prefix) { $prefix = "rdf"; } - $encoded_text = "\n <$prefix:Bag>"; - foreach my $bagitem (@{$text}) { - $encoded_text .= "\n <$prefix:li>"; - while ( $bagitem =~ s/(.*?)(\<\!\[CDATA\[.*?\]\]\>)//s ) { - $encoded_text .= encode_text($1) . $2; - } - $encoded_text .= encode_text($bagitem); - $encoded_text .= "</$prefix:li>"; - } - $encoded_text .= "\n </$prefix:Bag>\n"; - } - - else { + my ($self, $text) = @_; + return $text unless $self->{'encode_output'}; + + my $encoded_text = ''; + while ( $text =~ s/(.*?)(\<\!\[CDATA\[.*?\]\]\>)//s ) { - $encoded_text .= encode_text($1) . $2; + $encoded_text .= encode_text($1) . $2; } $encoded_text .= encode_text($text); - } - return $encoded_text; + + return $encoded_text; } sub encode_text {
Download (untitled) / with headers
text/plain 599b
On Tue Mar 29 12:40:03 2005, guest wrote: Show quoted text
> We had a number of cases where we wanted to keep RDF data in Bag > elements, but XML::RSS didn't support this, and if we tried to pass > them as > thing => " > <RDF:Bag> > <RDF:li>foo</RDF:li> > <RDF:li>bar</RDF:li> > </RDF:Bag>", > > everything got escaped, as it should, but that was not what we wanted. >
Hi, I don't really understand the use case for this. Can you refer me to a spec where it explains how this is supposed to be used? (If we add it, then I want a better and more general API for it than what you proposed). - ask
Download (untitled) / with headers
text/plain 265b
This issue is very old, and the original requester did not reply to ABH's query. I should note that one can over-ride the default behaviour for this particular case by creating a sub-class of ::Private::Output::... with a new _encode function. So I'm closing this.


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.