Subject: | Sorting entries in XML-Atom-SimpleFeed |
Date: | Thu, 24 Jan 2008 08:22:06 +0000 |
To: | bug-xml-atom-simplefeed [...] rt.cpan.org |
From: | "James Every" <james.every [...] gmail.com> |
Thank you for a very useful library! I have one question - my code
that generates my atom feed is merging events from various sources and
it is easier for me to sort the entries in time order when generating
the XML rather than adding the entries to the feed in the correct
order. I have added a sort call to the as_string method (see below
code from v0.7 though your v0.8 looks similar):
sub as_string
{
my $self = shift;
$self->{entries} = sort {$a->{issued} <=> $b->{issued} } @{
$self->{feed}[0]{entry} };
# This sorts the entries but wraps the root <feed...> in another <feed> tag!
my $xml = XMLout(
$self,
SuppressEmpty => 1,
RootName => 'feed',
KeepRoot => 1,
AttrIndent => 1
);
return $xml;
}
This code almost works but produces an extra unwanted outer <feed> tag:
<feed>
<feed version="0.3" xmlns="http://purl.org/atom/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
I understand this is more of a 'Perl' question than a 'SimpleFeed'
question but maybe you could suggest how to fix the sort line? My
Perl is very rusty I haven't used it in a few years!
Regards,
James