#!perl use strict; use DBI; use XML::Twig; my $dbh = dbh(); $dbh->do("DROP TABLE IF EXISTS ice_categories"); $dbh->do("CREATE TABLE ice_categories ( category_id int(11) not null, parent_cat_id int(11) not null, category_name varchar(100) not null default '', category_description varchar(100) not null default '', category_image varchar(100) not null default '', category_thumb varchar(100) not null default '', KEY (category_id), KEY (parent_cat_id)) CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); my $sql = 'INSERT INTO ice_categories ( category_id, parent_cat_id, category_name, category_description, category_image, category_thumb) VALUES (?,?,?,?,?,?)'; my $sth = $dbh->prepare($sql); my $t = XML::Twig->new( twig_handlers => { 'Category' => \&Category } ); $t->parsefile( 'file.xml' ); sub Category{ my ($t, $elt) = @_; my @f = ( $elt->att('ID') ); $f[4] = $elt->att('LowPic'); $f[5] = $elt->att('ThumbPic'); $f[1] = $elt->first_child('ParentCategory')->att('ID'); $f[2] = $elt->first_child('Name[@langid="1"]')->att('Value'); $f[3] = $elt->first_child('Description[@langid="1"]')->att('Value'); print "@f\n"; $sth->execute(@f); } # connect sub dbh { my $dsn = "DBI:mysql:database=test;host=localhost"; my $dbh = DBI->connect($dsn, 'user', 'password', {RaiseError => 1, PrintError => 1}) or die (Error connecting " $DBI::errstr"); }