First page Back Continue Last page Overview Graphics
Example 2: code
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $CATALOG_FILE = "plant_catalog.xml";
# a rather silly example of extracting information from a web page
# nparse creates a new twig and parses the argument (an html file here)
my $RATE = XML::Twig->nparse( "http://www.x-rates.com/index.html")
->first_elt( 'a[@href="/d/USD/EUR/graph120.html"]')
->text;
warn "rate: 1 EUR = $RATE USD\n";
my $catalog= XML::Twig->new( twig_roots => { price => \&price, },
twig_print_outside_roots => 1,
);
$catalog->parsefile( $CATALOG_FILE);
exit;