in reply to ORM for XML to DB - does one exist?
where %row is a hash representing the row data, with the field name as key and the value as value.$db->insert($table, \%row);
All you still have to do is extract the data from the XML and loading it into the hash (one row at a time).
If the data comes out of a web page, perhaps there's only one record per XML file? In that case, you might get along with just using XML::Simple, which does convert XML into a simple Perl data structure.
If you have the problem that the XML tagnames and the database field names don't fully agree, you can convert from one to the other using a mapping hash. For example if the XML has a tagnames (just making some names up now) "fullname" and "product-id" and the DB has the equivalent column names "name" and "product_id", you can map one to the other using
and you can do, getting the data out of %xmldata:%map = ( 'fullname' => 'name', 'product-id' => 'product_id' );
after which you can do the insert.my %row; @row{values %map} = @xmldata{keys %map};
If XML::Simple will not do you can use a module like XML::Twig (or my own XML::Parser::GlobEvents, which I wrote some 10 years ago, after the docs of the former module didn't make any sense to me) to build the data structure while parsing the XML.
|
|---|