#!/usr/bin/perl -w # # opml2html.pl, (c) Jeremy Zawodny -- http://jerermy.zawodny.com/blog/ # # Updated by Michael Radwin (http://www.radwin.org/michael/blog/) # on Dec 26th, 2003 to include image size attributes and link # titles. # # Updated by Brian Cantoni (http://www.cantoni.org/) on March 4, 2003 # to refer to the correct location for xml.gif (on my site) and to # break up the entries with
instead of bracketing each with

# tags. (These are just changes to tweak it better for my site.) # Also added HTML::Entities to properly encode the titles and # descriptions to ensure valid markup. # # You may distribute this code freely. It's not rocket science. # # Given an OPML file on stdin, produces an XHTML "blgoroll" fragment # suitable for inclusion on a weblog. Tested with AmphetaDesk and # Radio UserLand. # # Usage: opml2html.pl < foo.opml > bar.html # use strict; use XML::Simple; use Data::Dumper; use HTML::Entities; my $xml; { local($/) = undef; $xml = <>; } my $info = XML::Simple::XMLin($xml); my $data = $info->{body}->{outline}; my @list = sort { lc $a->{title} cmp lc $b->{title} } @$data; print qq[

]; for my $item (@list) { my $title = encode_entities($item->{title}); my $h_url = $item->{htmlurl}; $h_url =~ s/&/&/g; # replace ampersands -- this will break if URL already encoded! my $x_url = $item->{xmlurl}; $x_url =~ s/&/&/g; # ditto my $descr = encode_entities($item->{description}); print qq[XML\n]; print qq[$title
]; print "\n"; } print qq[

]; print "\n";