Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Converting RSS file to HTML

by Vautrin (Hermit)
on Mar 27, 2004 at 16:54 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-01-19 01:20 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (54 votes). Check out past polls.