in reply to Converting RSS file to HTML
RSS feeds are a form of XML. If you are unfamiliar with XML, you should read up on it. You may be able to use XSLT or XML Schema to automatically do what you want to do for you. And, you should use some kind of XML parser. Also, check out XML::Simple. You can use it to load the XML File into a combination of arrays and hashes. Then you could print out your HTML like so:
use strict; use warnings; use XML::Simple; my $parser = XML::Simple->new; my $hash = $parser->XMLin("./file"); # I'm not quite certain what data structure # will appear. Use Data::Dump or Data::Dumper # to find out. # note that custom quotes is new, and will break # under early versions of Perl print qq| <title>$hash->{item}->[0]->{title}</title> <a href="$hash->{item}=>[0]->{link}> $hash->{item}->[0]->{description}</a> |; # note that you could easily do this instead: # my @items = $hash->{item}; # foreach my $item (@items) { # # print stuff # }
Multiple XML tags which are the same will be in an array. So if you have more than one items you can do this, but be careful though. XML::Simple is supposed to be simple and easy to use, and thus doesn't do any kind of validation, and doesn't necessarily preserve the order of the XML. Go to CPAN and get a copy of another XML parser if you want to do something more complex. Oh, and never roll your own parser unless it's for educational purposes. It's not a good idea as there are plenty of parsers out there which include more work and effort then you would probably want to, and thus work much better.
|
|---|