First page Back Continue Last page Overview Graphics
Example 1: Code
-
#!/usr/bin/perl
-
use strict;
use warnings;
use DBI;
use XML::Twig;
-
my $CATALOG_FILE = "plant_catalog.xml";
my $DB_FILE = "plant_catalog.db";
-
my $dbh= DBI->connect("dbi:SQLite:dbname=$DB_FILE","","");
my $sth= $dbh->prepare( "INSERT into plant
( id, common, botanical, zone, light, price, availability)
VALUES( ?, ?, ?, ?, ?, ?, ?)");
-
XML::Twig->new( twig_handlers => { plant => \&store_plant })
->parsefile( $CATALOG_FILE);
-
sub store_plant
{ my( $t, $plant)= @_;
# the map... returns the list of text of all children of plant
$sth->execute( $plant->id, map { $_->text } $plant->children);
$t->purge;
}