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

Fellow Monasterians,

Doing my first XML coding and am running into a speed bump. The following returns a error:

use strict; use Data::Dumper; use XML::Simple; my $xml = new XML::Simple (KeyAttr=>[]); my $xmlresource = "http://prlmnks.org/rss/458722.xml"; my $feed = $xml->XMLin($xmlresource); #line 20 print "Content-type: text/html\n\n"; print Dumper($feed); ERROR: File does not exist: http://prlmnks.org/rss/458722.xml at /usr/www/use +rs/highgate/admin/cgi-bin/xmltest.pl line 20

If I upload a ____.xml file to the cgi-bin directory, it finds the file without incident. The XML::Simple docs mention *file* but not URL. So, how, or with what module, would I use to pull in an xml file for parsing? Thanks!


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: Pulling in an RSS feed for parsing
by ikegami (Patriarch) on Jun 06, 2005 at 18:29 UTC
Re: Pulling in an RSS feed for parsing
by davidrw (Prior) on Jun 06, 2005 at 18:36 UTC
    You can use LWP::Simple to grab the file and send the contents to XMLin(), which can accept a string.
    my $xmlresource = "http://prlmnks.org/rss/458722.xml"; use LWP::Simple; my $xmlstring = get $xmlresource; my $feed = $xml->XMLin($xmlstring);

      Both replies were right on. I tried LWP::Simple and it worked like a charm. I did have to drop the OO $xml->. Anyway, big day for this monk.


      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Pulling in an RSS feed for parsing
by wolv (Pilgrim) on Jun 06, 2005 at 23:22 UTC
    Also, see URI::Fetch. It does a few things for you - last-modified headers and ungzipping, and such. Nothing you can't code yourself, but that's what CPAN is for, right? :)
Re: Pulling in an RSS feed for parsing
by reneeb (Chaplain) on Jun 07, 2005 at 08:55 UTC
    To parse RSS-files, I would recommend to use XML::RSS...

      Last time I checked XML::RSS leaked memory like there's no tomorrow, so I ended up writing my own parser based on XML::LibXML. XML::RSS surely useful, but you have to be careful with it, especially when you use it in a long-running process.

        Ever plan on releasing your module into CPAN?

            -Bryan