Thread CSV 2 XML Datenkonverter: Perlprogramm, dass CSV zu XML umwandelt (38 answers)
Opened by Gast at 2005-01-25 10:39

renee
 2005-01-25 11:37
#51261 #51261
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Probier mal:
Code: (dl )
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
#! /usr/bin/perl

use strict;
use warnings;
use DBI;
use XML::Writer;
use IO::File;

my $output = new IO::File(">output.xml");
my $writer = new XML::Writer(OUTPUT => $output);

my $dbh = DBI->connect("DBI:CSV:csv_sep_char=\\;") or die $DBI::errstr;
$dbh->{'csv_tables'}->{'info'} = { 'file' => 'info.csv'};
my $sth = $dbh->prepare("SELECT * FROM info");
$sth->execute();
my @names = @{$sth->{NAME}};
while(my @row = $sth->fetchrow_array()){
 for(0..$#names){
   $writer->startTag($names[$_]);
   $writer->characters($row[$_]);
   $writer->endTag($names[$_]);
 }
}
$sth->finish();
$dbh->disconnect();

$writer->end();
$output->close();
\n\n

<!--EDIT|renee|1106646459-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread CSV 2 XML Datenkonverter: Perlprogramm, dass CSV zu XML umwandelt