#!perl use strict; use XML::Twig::XPath; use LWP::Simple; use HTML::Template; use Data::Dump 'pp'; # XML parser my $twig = XML::Twig::XPath->new( twig_roots => { '/find/find/work[@eu]' => \&work, }, ); # get and process xml my @rows = (); my $URL = 'http://www.geocities.ws/arenas/xml/find.xml'; #$twig->parse( *DATA ); #test with __DATA__ records $twig->parse( LWP::Simple::get( $URL ) ); pp \@rows; # prepare html template and parameters my $template = get_template(); my $t = HTML::Template->new( scalarref => \$template ); $t->param( EU => \@rows ); # create html open my $fh_out,'>','val.html' or die "$!"; print $t->output( print_to => $fh_out ); close $fh_out; # extract data from work node sub work { my ($twig,$el) = @_; for my $ch ($el->children){ my %rec = ( 'name' => $ch->name ); $rec{$_} = $ch->att($_) for ('a'..'f'); push @rows,\%rec; } } #### # or put in file sub get_template { return < Title
Name a b c d e f
EOF } __DATA__