Mach:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/perl
use strict;
use warnings;
use DBI;
use XML::Writer;
use IO::File;
my $output = new IO::File(">output.xml"); die $! unless($output);
my $writer = new XML::Writer(OUTPUT => $output);
my $dbh = DBI->connect("DBI:CSV:f_dir=C:/;csv_sep_char=\\;") or die $DBI::errstr;
$dbh->{'csv_tables'}->{'info'} = { 'file' => 'info2.csv'};
my $sth = $dbh->prepare("SELECT * FROM info");
$sth->execute();
my @names = @{$sth->{NAME}};
$writer->startTag('Entries');
while(my @row = $sth->fetchrow_array()){
$writer->startTag('Entry');
$writer->characters("\n");
for(0..$#names){
$writer->startTag($names[$_]);
$writer->characters($row[$_]);
$writer->endTag($names[$_]);
$writer->characters("\n");
}
$writer->endTag('Entry');
}
$writer->endTag('Entries');
$sth->finish();
$dbh->disconnect();
$writer->end();
$output->close();
Jetzt sollte es funktionieren...