bcnagle has asked for the wisdom of the Perl Monks concerning the following question:
Great Monks of Perl. I beseech your guidance. I have tried to use XML::Twig however upon executing the script file, my server is not equipped and can't debug the XS version of Scalar::Util so went to XML::Parser SAX for my execution. It seems to be doing ok however I am getting an error on execution that probably is trivial but I am a total nub with Linux and I do apologize for that. The Code is as Follows along with the error code. Thank you for your assistance.
# !/usr/local/bin/perl -w BEGIN { my $base_module_dir = (-d '/home/bcnagle/perl' ? '/home/bcnagle/pe +rl' : ( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } use strict; use DBI; use XML::Parser::PerlSAX; my $path; my $Product_ID; my $Updated; my $Quality; my $Supplier_id; my $Prod_ID; my $Catid; my $On_Market; my $Model_Name; my $Product_View; my $HighPic; my $HighPicSize; my $HighPicWidth; my $HighPicHeight; my $Date_Added; my $dbh= connect_to_db(); my $insert= $dbh->prepare( "INSERT INTO files (path, Product_ID, Upda +ted, Quality, Supplier_id, Prod_ID, Catid, On_Market, Model_Name, Pro +duct_View, HighPic, HighPicSize, HighPicWidth, HighPicHeight, Date_Ad +ded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); $insert->bind_param( 1, $path); $insert->bind_param( 2, $Product_ID); $insert->bind_param( 3, $Updated); $insert->bind_param( 4, $Quality); $insert->bind_param( 5, $Supplier_id); $insert->bind_param( 6, $Prod_ID); $insert->bind_param( 7, $Catid); $insert->bind_param( 8, $On_Market); $insert->bind_param( 9, $Model_Name); $insert->bind_param( 10, $Product_View); $insert->bind_param( 11, $HighPic); $insert->bind_param( 12, $HighPicSize); $insert->bind_param( 13, $HighPicWidth); $insert->bind_param( 14, $HighPicHeight); $insert->bind_param( 15, $Date_Added); my $twig = new XML::Parser(); $twig->parse( "/home/bcnagle/public_html/files.index.xml" ); $dbh->disconnect(); exit; sub connect_to_db { my $driver = "mysql"; my $dsn = "DBI:$driver:database=database;"; my $dbh = DBI->connect($dsn, 'uname', 'pword', {AutoCommit=>1}); my $drh = DBI->install_driver($driver); return( $dbh); } sub start_element { my($twig, $file) = @_; if ($file->{Name} eq 'file') { $path = $file->{Attributes}->{'path'}; $Product_ID = $file->{Attributes}->{'Product_ID'}; $Updated = $file->{Attributes}->{'Updated'}; $Quality = $file->{Attributes}->{'Quality'}; $Supplier_id = $file->{Attributes}->{'Supplier_id'}; $Prod_ID = $file->{Attributes}->{'Prod_ID'}; $Catid = $file->{Attributes}->{'Catid'}; $On_Market = $file->{Attributes}->{'On_Market'}; $Model_Name = $file->{Attributes}->{'Model_Name'}; $Product_View = $file->{Attributes}->{'Product_View'}; $HighPic = $file->{Attributes}->{'HighPic'}; $HighPicSize = $file->{Attributes}->{'HighPicSize'}; $HighPicWidth = $file->{Attributes}->{'HighPicWidth'}; $HighPicHeight = $file->{Attributes}->{'HighPicHeight'}; $Date_Added = $file->{Attributes}->{'Date_Added'}; $insert->execute(); $twig->purge; exit; #debug and testing purpose, write 1 line then exit. } else { #do nothing } } sub end_element { } sub start_document { } sub end_document { exit; }
I am connecting to the Database just fine but when it starts the handlers it gives this error:
not well-formed (invalid token) at line 1, column 0, byte 0 at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/Parser.pm line 187
I think it has to do with the first line of the xml but am not positive. the xml sheet which I cannot edit due to it coming straight from the supplier is as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ICECAT-interface SYSTEM "http://data.icecat.biz/dtd/files.in +dex.dtd"> <!-- source: ICEcat.biz 2011 --> <ICECAT-interface xsi:noNamespaceSchemaLocation="http://data.icecat.bi +z/xsd/files.index.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in +stance"> <files.index Generated="20110712102037"> <file Date_Added="2 +0050627000000" HighPicHeight="200" HighPicWidth="320" HighPicSize="13 +817" HighPic="http://images.icecat.biz/img/norm/high/19311-1470.jpg" +Product_View="15591" Model_Name="016166400" On_Market="1" Catid="978" + Prod_ID="016166400" Supplier_id="30" Quality="ICECAT" Updated="20110 +711025126" Product_ID="19311" path="export/freexml.int/EN/19311.xml"> + <EAN_UPCS> <EAN_UPC Value="0042215447881"/> <EAN_UPC Value="04221544 +78816"/> </EAN_UPCS> <Country_Markets> <Country_Market Value="FR"/> < +Country_Market Value="UK"/> <Country_Market Value="DE"/> <Country_Mar +ket Value="DK"/> <Country_Market Value="PL"/> <Country_Market Value=" +CH"/> <Country_Market Value="CZ"/> <Country_Market Value="AT"/> </Cou +ntry_Markets> </file>...repeat with new items and so on to a total of + approximately a 1gb file </files.index> </ICECAT-interface>
Any assistance would be most grateful. Thank you for your time, Brian
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Parser SAX error
by graff (Chancellor) on Jul 16, 2011 at 05:10 UTC | |
by bcnagle (Novice) on Jul 16, 2011 at 05:30 UTC | |
by graff (Chancellor) on Jul 16, 2011 at 06:04 UTC | |
by bcnagle (Novice) on Jul 16, 2011 at 07:24 UTC | |
by bcnagle (Novice) on Jul 16, 2011 at 05:33 UTC | |
|
Re: XML::Parser SAX error
by Anonymous Monk on Jul 16, 2011 at 05:55 UTC | |
by bcnagle (Novice) on Jul 16, 2011 at 06:05 UTC |