I recommend using SQL::Abstract, possibly on top of DBIx::Simple. In this case, inserting the data into the DB is as simple as:
$db->insert($table, \%row);
where %row is a hash representing the row data, with the field name as key and the value as value.

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

%map = ( 'fullname' => 'name', 'product-id' => 'product_id' );
and you can do, getting the data out of %xmldata:
my %row; @row{values %map} = @xmldata{keys %map};
after which you can do the insert.

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.


In reply to Re: ORM for XML to DB - does one exist? by bart
in thread ORM for XML to DB - does one exist? by learnedbyerror

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, details, 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, summary, 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.