Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Error when creating a new instance of XML::Writer

by ev0lution (Initiate)
on Nov 08, 2012 at 20:07 UTC ( #1002975=perlquestion: print w/replies, xml ) Need Help??
ev0lution has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to implement XML::Writer to help dump a MySQL database to XML format, however I'm getting the following error:

Can't locate object method "new" via package "XML::Writer" at /apollo/volume/software/application/artemis/bin/ line 371.

I'm implementing the code as a subroutine, but when I initially had it running locally as it's own script it was functioning just file. Here's the spot of code that is giving me the problems. FYI, I did load the module at the beginning of the script (use XML::Writer;) and it is installed. It seems that it is trying to find the 'new()' function within the XML::Writer module, but can't find it. No clue why not. Thanks in advance for the help!
sub SQLtoXML { $log->debug("Attempting to pull from MySQL DB and write to XML.." . +"\n"); #Parameter being passed is the Source ID to check against the Databa +se and final directory for XML file. my $PassedSource = $_[0]; my $FinalDir = $_[1]; my $FileName = ""; #Set up temporary XML output file for XML::Writer my $output = IO::File->new(">output.xml"); #Initiate XML::Writer my $writer = XML::Writer->new(OUTPUT => $output);

Replies are listed 'Best First'.
Re: Error when creating a new instance of XML::Writer
by fishmonger (Chaplain) on Nov 08, 2012 at 21:06 UTC
Re: Error when creating a new instance of XML::Writer
by karlgoethebier (Monsignor) on Nov 09, 2012 at 10:20 UTC

    You can get the XML from mysql for free.

    mysqldump --xml --compact dbname > out.xml


    my $db=qq(classicmodels); my $xml= qx(mysqldump --xml --compact $db);
    <?xml version="1.0"?> <mysqldump xmlns:xsi=""> <database name="classicmodels"> <table_structure name="customers"> <field Field="customerNumber" Type="int(11)" Null="NO" Key="PR +I" Extra="" Comment="" /> <field Field="customerName" Type="varchar(50)" Null="NO" Key=" +" Extra="" Comment="" /> <field Field="contactLastName" Type="varchar(50)" Null="NO" Ke +y="" Extra="" Comment="" /> <field Field="contactFirstName" Type="varchar(50)" Null="NO" K +ey="" Extra="" Comment="" /> <field Field="phone" Type="varchar(50)" Null="NO" Key="" Extra +="" Comment="" /> <field Field="addressLine1" Type="varchar(50)" Null="NO" Key=" +" Extra="" Comment="" /> <field Field="addressLine2" Type="varchar(50)" Null="YES" Key= +"" Extra="" Comment="" /> <field Field="city" Type="varchar(50)" Null="NO" Key="" Extra= +"" Comment="" /> <field Field="state" Type="varchar(50)" Null="YES" Key="" Extr +a="" Comment="" /> <field Field="postalCode" Type="varchar(15)" Null="YES" Key="" + Extra="" Comment="" /> <field Field="country" Type="varchar(50)" Null="NO" Key="" Ext +ra="" Comment="" /> <field Field="salesRepEmployeeNumber" Type="int(11)" Null="YES +" Key="" Extra="" Comment="" /> <field Field="creditLimit" Type="double" Null="YES" Key="" Ext +ra="" Comment="" /> <key Table="customers" Non_unique="0" Key_name="PRIMARY" Seq_i +n_index="1" Column_name="customerNumber" Collation="A" Cardinality="1 +22" Null="" Index_type="BTREE" Comment="" Index_comment="" /> <options Name="customers" Engine="MyISAM" Version="10" Row_for +mat="Dynamic" Rows="122" Avg_row_length="114" Data_length="13992" Max +_data_length="281474976710655" Index_length="4096" Data_free="0" Crea +te_time="2012-11-09 09:53:36" Update_time="2012-11-09 09:53:36" Colla +tion="latin1_swedish_ci" Create_options="" Comment="" /> </table_structure> <table_data name="customers"> <row> <field name="customerNumber">103</field> <field name="customerName">Atelier graphique</field> <field name="contactLastName">Schmitt</field> <field name="contactFirstName">Carine </field> <field name="phone">40.32.2555</field> <field name="addressLine1">54, rue Royale</field> <field name="addressLine2" xsi:nil="true" /> <field name="city">Nantes</field> <field name="state" xsi:nil="true" /> <field name="postalCode">44000</field> <field name="country">France</field> <field name="salesRepEmployeeNumber">1370</field> <field name="creditLimit">21000</field> </row> <!-- Skipped the next 20.000 lines... -->

    If that is it what you want.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»
Re: Error when creating a new instance of XML::Writer
by bitingduck (Chaplain) on Nov 09, 2012 at 06:57 UTC
    What version of Perl are you using and on what system? I had a similar problem with a different module on a particular install of 5.10.1 (a mac running Snow Leopard, and the 5.10.1 that was part of the dev tools). Other installs of 5.10.1 didn't show the problem, nor did later versions of Perl. I never did sort out exactly why it happened. You should try running the test script that fishmonger gave you, and if that fails, try running it on some other installs.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002975]
Approved by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-02-25 14:12 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.