Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Converting RSS file to HTML

by Vautrin (Hermit)
on Mar 27, 2004 at 16:54 UTC ( [id://340279]=note: print w/replies, xml ) Need Help??


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.


Want to support the EFF and FSF by buying cool stuff? Click here.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://340279]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found