subeen has asked for the wisdom of the Perl Monks concerning the following question:

hello,

I am trying to parse a RSS file using XML::RSS but got stuck when I tried to read the following from items:

<media:content url="http://www.media.com" type="video/windows-wmv" med +ium="video" width="416" height="312"> <media:keywords>Bill, Concert with Bill</media:keywords> <dcterms:valid> start=2005-06-13T00:00:00; end=2005-12-31T00:00:00; scheme=W3C-DTF </dcterms:valid> </media:content>
I tried $media_keyword = $item->{'media:keywords'}; to read the keywords but it shows nothing. I also want to read the media content url. Please see the example in http://www.feedforall.com/mediarss.htm I am trying to parse similar rss.

Made some progress with add_module.

$rss->add_module(prefix=>'dc', uri=>"http://purl.org/dc/terms/"); $rss->add_module(prefix=>'media', uri=>"http://search.yahoo.com/mrss") +; $rss->parse($raw); foreach my $item (@{$rss->{'items'}}) { $title = $item->{'title'}; $media_content_url = $item->{'media'}->{'content'}->{'url'}; $media_keywords = $item->{'media'}->{'keywords'}; print $title, "\n"; print $media_content_url, "\n"; print $media_keywords, "\n"; }
It prints title and media_keywords, but doesn't show anything for media_content_url. BTW. The RSS I am trying to parse is RSS 2

Thanks, Subeen.

Replies are listed 'Best First'.
Re: RSS Parse Problem with XML::RSS
by hossman (Prior) on Sep 16, 2007 at 07:35 UTC

    You should read the docs for XML::RSS ... in particular look for the method add_module and the section on "RSS 1.0 MODULES"

      Made some progress with add_module.
      $rss->add_module(prefix=>'dc', uri=>"http://purl.org/dc/terms/"); $rss->add_module(prefix=>'media', uri=>"http://search.yahoo.com/mrss") +; $rss->parse($raw); foreach my $item (@{$rss->{'items'}}) { $title = $item->{'title'}; $media_content_url = $item->{'media'}->{'content'}->{'url'}; $media_keywords = $item->{'media'}->{'keywords'}; print $title, "\n"; print $media_content_url, "\n"; print $media_keywords, "\n"; }
      It prints title and media_keywords, but doesn't show anything for media_content_url. BTW. The RSS I am trying to parse is RSS 2

      Thanks, Subeen.

        Did you try $rss->{link} for the URL?

        You can also use Data::Dumper to inspect $item to see which hash keys are available.