Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading/parsing an .xml file to display info on my site...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have this module on my server:

XML::parser;

but not this one:

XML::RSS;

Am I still able access an external .xml file such as
Thanks.

- g
 
Yes. You could always pull the file over using lwp if you wanted it local.
 
i'm able to do that already, but i don't know how to parse the file from there...

i found this:

Code:
#!/usr/bin/perl
use CGI::Carp 'fatalsToBrowser';
use XML::Parser;
use LWP::Simple;

$feed;

open( FH, ">feed.xml") or die "Error: $!\n";

$feed = get("[URL unfurl="true"]http://rss.news.yahoo.com/rss/topstories");[/URL]

print FH $feed;


$parser = new XML::Parser ( Handlers => {
                               Start   => \&hdl_start,
                               End     => \&hdl_end,
                               Char    => \&hdl_char,
                             } );
                                                                      
+                                                                    
$parser->parsefile("feed.xml");

sub hdl_start {

    ($p, $ele, %attribs) = @_;
    $attribs{'string'} = '';
    $feed = \%attribs;
}

sub hdl_end {                                                         
+       

    ($p, $ele) = @_;
    display_feed($feed) if $ele eq 'title';
    display_feed($feed) if $ele eq 'link';
}

sub hdl_char {

   ($p, $str) = @_;
   no strict 'refs';

   $feed->{'string'} .= $str;
}

sub display_feed {

   $attribs = shift;
   $attribs =~ s/\n//g;

   print "$attribs->{'string'}\n\n";
}

this seems to work, but i only seems to work on a yahoo xml file...

since i don't know much of this module, i don't know what or how to change it to read other rss feeds.

any ideas?

- g
 
Have a look at the RSS file that works and one that doesn't to see if you can spot a difference in structure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top