#!/usr/bin/perl use warnings; use strict; use XML::Twig; my $twig= XML::Twig->new( twig_handlers => { 'RDF/Topic' => \&topic, 'RDF/ExternalPage' => \&extpage } ); $twig->parsefile( './sample.xml'); # my $base_dir = 'F:/httpserv'; # chdir $base_dir or die "Failed to chdir to $base_dir: $!\n"; { my %links; sub topic { my ( $twig, $topic ) = @_; if ( $topic->children('link')) { # my $dir = $topic->att('r:id'); # chdir $dir or "Failed to chdir to $dir: $!\n"; $links{ $_->att('r:resource') } = $_ for $topic->children('link'); } else { %links = (); } $twig->purge; } sub extpage { my ( $twig, $extpage ) = @_; if ( exists $links{ $extpage->att( 'about' ) } ) { print $extpage->first_child_text('d:Title'), "\n"; print $extpage->first_child_text('d:Description'), "\n"; } $twig->purge; # chdir $base_dir or die "Failed to chdir to $base_dir: $!"; } } __END__ British Horror Films: 10 Rillington Place Review which looks at plot especially the shocking features of it. MMI Movie Review: 10 Rillington Place Review includes plot, real life story behind the film and realism in the film.