#!/usr/bin/perl -- use strict; use warnings; use Data::Dumper; use XML::Simple; my $xml = q~<?xml version="1.0"?> <rss version="2.0"> <channel> <title>Example 2.0 Channel with Enclosure sub-element of Item</title +> <link>http://example.com/</link> <description>To lead by example</description> <language>en-us</language> <copyright>All content Public Domain, except comments which remains +copyright the author</copyright> <managingEditor>editor@example.com</managingEditor> <webMaster>webmaster@example.com</webMaster> <docs>http://backend.userland.com/rss</docs> <category domain="http://www.dmoz.org">Reference/Libraries/Library_ +and_Information_Science/Technical_Services/Cataloguing/Metadata/RDF/A +pplications/RSS/</category> <generator>The Superest Dooperest RSS Generator</generator> <lastBuildDate>Mon, 02 Sep 2002 03:19:17 GMT</lastBuildDate> <ttl>60</ttl> <item> <title>News for September the Second</title> <link>http://example.com/2002/09/02</link> <description>other things happened today</description> <comments>http://example.com/2002/09/02/comments.html</comments> <author>joeuser@example.com</author> <pubDate>Mon, 02 Sep 2002 03:19:00 GMT</pubDate> <guid isPermaLink="true">http://example.com/2002/09/02</guid> <enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp +3" length="12216320" type="audio/mpeg" /> </item> <item> <title>22News for September the Second</title> <link>http://22example.com/2002/09/02</link> <description>22other things happened today</description> <comments>http://22example.com/2002/09/02/comments.html</comments> <author>22joeuser@22example.com</author> <pubDate>Mon, 22 Sep 2002 03:19:00 GMT</pubDate> <guid isPermaLink="true">http://22example.com/2002/09/02</guid> <enclosure url="http://www.22scripting.com/mp3s/22weatherReportSuit +e.mp3" length="12216320" type="audio/mpeg" /> </item> </channel> </rss>~; $xml = XMLin( $xml, ForceArray => ['item'], ); local $Data::Dumper::Indent=1; print Dumper( $xml ),"\n"; my $items = $xml->{channel}{item}; for my $i( @$items ){ print $i->{enclosure}{url},"\n"; } __END__ $VAR1 = { 'version' => '2.0', 'channel' => { 'link' => 'http://example.com/', 'language' => 'en-us', 'ttl' => '60', 'item' => [ { 'enclosure' => { 'length' => '12216320', 'url' => 'http://www.scripting.com/mp3s/weatherReportSuite.m +p3', 'type' => 'audio/mpeg' }, 'link' => 'http://example.com/2002/09/02', 'author' => 'joeuser@example.com', 'comments' => 'http://example.com/2002/09/02/comments.html', 'description' => 'other things happened today', 'title' => 'News for September the Second', 'guid' => { 'isPermaLink' => 'true', 'content' => 'http://example.com/2002/09/02' }, 'pubDate' => 'Mon, 02 Sep 2002 03:19:00 GMT' }, { 'enclosure' => { 'length' => '12216320', 'url' => 'http://www.22scripting.com/mp3s/22weatherReportSui +te.mp3', 'type' => 'audio/mpeg' }, 'link' => 'http://22example.com/2002/09/02', 'author' => '22joeuser@22example.com', 'comments' => 'http://22example.com/2002/09/02/comments.html', 'description' => '22other things happened today', 'title' => '22News for September the Second', 'guid' => { 'isPermaLink' => 'true', 'content' => 'http://22example.com/2002/09/02' }, 'pubDate' => 'Mon, 22 Sep 2002 03:19:00 GMT' } ], 'copyright' => 'All content Public Domain, except comments which r +emains copyright the author', 'description' => 'To lead by example', 'generator' => 'The Superest Dooperest RSS Generator', 'lastBuildDate' => 'Mon, 02 Sep 2002 03:19:17 GMT', 'category' => { 'domain' => 'http://www.dmoz.org', 'content' => 'Reference/Libraries/Library_and_Information_Scienc +e/Technical_Services/Cataloguing/Metadata/RDF/Applications/RSS/' }, 'title' => 'Example 2.0 Channel with Enclosure sub-element of Item +', 'webMaster' => 'webmaster@example.com', 'docs' => 'http://backend.userland.com/rss', 'managingEditor' => 'editor@example.com' } }; http://www.scripting.com/mp3s/weatherReportSuite.mp3 http://www.22scripting.com/mp3s/22weatherReportSuite.mp3
In reply to Re^2: XML::RSS:Parser not reading enclosure tags
by Anonymous Monk
in thread XML::RSS:Parser not reading enclosure tags
by Massyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |