Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!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"); }
poj

In reply to Re^3: Perl XML::Smart Out of memory! error by poj
in thread Perl XML::Smart Out of memory! error by nasaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2019-03-19 23:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How do you Carpe diem?





      Results (96 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!