XML::RSS is alive and getting better.

brian_d_foy on 2002-11-14T20:59:58

I took over the XML::RSS module from Jonathan Eisenkopf thinking I could make a couple of quick fixes, release a new version, and everyone would be happy.

Instead, all sorts of other people came out of the woodwork with even more things to add. I just added them to the SourceForge project, which now has 6 members, and some of them have already committed their own changes.

I cleared one of the tickets in RT, and now I have one left, but one of the project members has a patch for this too. It is a little more complicated so I cannot clear the ticket right away.

Anyone interested in working on some part of XML:RSS? We could use help with almost anything, including maintaining a useful and visually pleasing website, tutorial writer, and project historian. Let's make XML::RSS the gold standard again. Volunteers?


Feature request

pudge on 2002-11-14T21:14:33

perl -MXML::RSS -MLWP::Simple -MData::Dumper -le '$t = get("http://freshmeat.net/backend/fm-releases-themes.rdf"); $x = new XML::RSS; $x->parse($t); for (keys %{$x->{namespaces}}) { next if $_ eq "rdf" || $_ eq "#default" || exists $x->{modules}{$x->{namespaces}{$_}}; $x->add_module(prefix => $_, uri => $x->{namespaces}{$_}) }; $x = new XML::RSS; $x->parse($t); print Dumper $x->{items}[0]'
This auto-populates the namespaces with the declared namespaces. So this file has:
xmlns:fm="http://freshmeat.net/backend/fm-releases-0.1.dtd"
And normally, XML::RSS just puts http://freshmeat.net/backend/fm-releases-0.1.dtd as the namespace for the items belonging to that module. That code above creates an fm namespace automatically (and then both work).

I've not looked into this in awhile, but it's something I wanted, so I've saved the code snippet since May, waiting for TODAY to give it to YOU!

Re:Feature request

brian_d_foy on 2002-11-14T21:38:37

That's a pretty long one-liner :)

Let me restate the request to see if I understand what you want:


XML::RSS should access Freshmeat's feed and automatically pull out whatever is in xmlns:fm, then add that as a module.


I do not want to do that for every object. Perhaps a more specific method like "add_freshmeat" so the module only loads LWP if you specifically want that to happen.

I can also add any common, but missing, namespaces to the default list.

I'm fairly new to the RSS world, so someone needs to point out the land mines before I do this. :)

Re:Feature request

pudge on 2002-11-14T22:07:41

No, lemme try again.

I just want to have add_module() called automatically for every nonstandard module in the feed. The real important code is here:

# loop over existing namespaces
for my $ns (keys %{$rss->{namespaces}}) {
   # skip default namespaces
   next if $ns eq "rdf"
        || $ns eq "#default"
        || exists $rss->{modules}{ $ns->{namespaces}{$ns} };
   $rss->add_module(prefix => $ns, uri => $rss->{namespaces}{$ns})
}
This does not need to invoke LWP. The only practical effect is that instead of someone needing to do this:
my $ns = 'http://freshmeat.net/backend/fm-releases-0.1.dtd';
for my $item ( @{$rss->{items}} ) {
   print $item->{$ns}{screenshot_url};
}
They can do this:
for my $item ( @{$rss->{items}} ) {
   print $item->{fm}{screenshot_url};
}
The one-liner:
  1. fetches the RSS
  2. parses the RSS
  3. looks for nonstandard namespaces
  4. adds each namespaces with add_module (which sets up the fm => 'http://freshmeat.net/backend/fm-releases-0.1.dtd' mapping)
  5. reparses the XML
  6. uses the new RSS
A patch implementing the code near the top would ideally skip the 5th item, and do the 3rd and 4th inside the 2nd. I believe I asked once for this to be included, but the response back was that one should know in advance what modules one is expecting. That is, you can all add_module before parsing the RSS. But a lot of times, you don't know what namespaces you will be expecting. Maybe a flag in the new constructor, add_modules => 1, or something, would be in order.

Re:Feature request

brian_d_foy on 2002-11-14T22:25:52

Okay, I think I got this now. Automatically call add_module() for all of the namespaces in the file I have to parse. That makes sense.

Would you like to paste this into RT as a feature request? it's not going to happen this week because we have a long queue of patches for broken things (which come first).

Re:Feature request

pudge on 2002-11-18T15:23:38

Added, thanks.