warsting has asked for the wisdom of the Perl Monks concerning the following question:
The following is a snippet from my code to allow for testing to get the actual logic to work. I have used a similar functionality in a CSV format and it worked but when I try to use it in a XML format it won't save to a XML file, even when I "export" it.
Installed Perl modules to support the functionality:
* DBI
* SQL::Statement
* DBD::File
* AnyData
* DBD::AnyData
* XML::Twig
* XML::Parse
I've left in the comments where the error occurs and what the error messages shows. Also shows all the "attempts" (should say "failures") in the comments below.
Thanks for any help or suggestions,
warsting
use DBI; $name = 'Testing'; $agency = 'TT'; $email = 'test@abc.com'; $org = 'ABC'; $mailstop = 'X159'; $phone = '(555) 123-4567'; $title = 'Other'; $DATA_COLUMNS = 'name,agency,email,org,mailstop,phone,title'; # tried it with/without the 'eadata' tag too (ie '/eadata/user/name' f +or the first one) $XML_COL_MAP = [ {'/eadata/user/name','name'}, {'/eadata/user/agency','agency'}, {'/eadata/user/email','email'}, {'/eadata/user/org','org'}, {'/eadata/user/mailstop','mailstop'}, {'/eadata/user/phone','phone'}, {'/eadata/user/title','title'} ]; # open a new connection to the XML file (user.xml) $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); #$dbh->func('users', 'XML', './users.xml', {col_names => $DATA_COLUMNS +, col_map => $XML_COL_MAP}, 'ad_import'); # XML file added below for ease of testing $dbh->func('users', 'XML', [<DATA>], {col_names => $DATA_COLUMNS, col_ +map => $XML_COL_MAP}, 'ad_import'); #$dbh->func('users', 'XML', [<DATA>], {col_names => $DATA_COLUMNS}, 'a +d_import'); # insert a new record in to the memory table 'users' $SQL = qq{insert into users($DATA_COLUMNS) values('$name','$agency','$email','$org','$mailstop','$phone +','$title')}; $dbh->do($SQL); # export out to a new file (users_new.xml) $dbh->func('users', 'XML', './users_new.xml', {col_names => $DATA_COLU +MNS, col_map => $XML_COL_MAP}, 'ad_export'); #$dbh->func('users', 'XML', './users_new.xml', {col_names => $DATA_COL +UMNS}, 'ad_export'); # getting this error (no matter which line above I try)): # SQL ERROR: Bad table or column name '1' starts with non-alphabetic + character! # -- actually errors twice # close the database and closes the file $dbh->disconnect; # this is from the xml file (users.xml), places here for ease of testi +ng __END__ <eadata> <user> <name>Testing Tester</name> <agency>LL</agency> <email>test4@abc.net</email> <org>Test</org> <mailstop>T125</mailstop> <phone>98765</phone> <title>Other</title> </user> <user> <name>Walt Arsting...</name> <agency>XX</agency> <email>arsting...@xyz.net</email> <org>ASQ</org> <mailstop>L339</mailstop> <phone>555-123-4567</phone> <title></title> </user> </eadata>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Saving data to XML file using DBD::AnyData
by snoopy (Curate) on Dec 04, 2009 at 07:02 UTC | |
by warsting (Novice) on Dec 04, 2009 at 17:01 UTC | |
|
Re: Saving data to XML file using DBD::AnyData
by stefbv (Priest) on Dec 04, 2009 at 08:10 UTC | |
by warsting (Novice) on Dec 04, 2009 at 17:33 UTC | |
by stefbv (Priest) on Dec 04, 2009 at 19:21 UTC | |
by warsting (Novice) on Dec 07, 2009 at 15:13 UTC |