Since DBIx::XML_RDB has been replaced by the new and improved XML::Generator::DBI - here is a much better way to convert CSV to XML:
use strict; use DBI; use File::Basename; use XML::Generator::DBI; use XML::Handler::YAWriter; my $dir = '.'; my $file = 'foo.csv'; my $table = (fileparse($file,'.csv'))[0]; my $cols = [qw(name id date)]; my $sep = ','; my $dbh = DBI->connect( "DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=$sep;", {RaiseError=>1}, ); $dbh->{csv_tables}->{$table} = { file => $file, col_names => $cols, }; my $ya = XML::Handler::YAWriter->new(AsFile => "-"); my $generator = XML::Generator::DBI->new( Handler => $ya, dbh => $dbh, Indent => 1, ); $generator->execute("select * from $table");
Much better, but i still enjoy a little OO hacking now and then. :D

UPDATE:
Silly /me - XML::CSV:

perl -MXML::CSV -e '$o=XML::CSV->new;$o->parse_doc(shift,{headings=>sh +ift});$o->print_xml' no_headings.csv perl -MXML::CSV -e '$o=XML::CSV->new;$o->parse_doc(shift,{headings=>sh +ift});$o->print_xml' headings.csv 1

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to CSV to XML (the quick and not so dirty way) by jeffa
in thread CSV to XML (the quick and dirty way) by jeffa

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.