Y
yann.pambou
Hi,
I'm converting a XML file into a .csv file. It works pretty well for
small XML files, but it doesn't work for big files ~150MB. My script
stops and gives me a memory problem message.
Anyone has any idea?
Here is the script that i'm using: Thanks,
#!/usr/bin/perl -w
## Remove commas
use warnings;
use strict;
use XML::XPath;
open (BLANK, "XML/Verizon.xml");
open (BLANK2, ">XML/Verizon2.xml");
## Align tags and values
my $blank = "";
while ($blank = <BLANK>) {
if ($blank =~ /^\s*$/) {
chomp($blank);
}
else {
$blank =~ s/,//g;
print BLANK2 $blank;
}
}
close (BLANK);
close (BLANK2);
iopen (DATA, "XML/Verizon2.xml");
open (FILE, ">import.csv");
my ($xp) = XML::XPath->new( join('', <DATA>) );
my(@records) = $xp->findnodes( '/TroubleTickets/TroubleTicket' );
my($firstTime) = 0;
foreach my $record ( @records ) {
my(@fields) = $xp->find( './child::*', $record )->get_nodelist();
unless ( $firstTime++ ) {
# print( join( ',', map { $_->getName() } @fields ), "\n");
print FILE ( join( ',', map { $_->getName() } @fields ), "\n");
}
# print( join( ',', map { $_->string_value() } @fields ), "\n");
my $test = join( ',', map { $_->string_value() } @fields );
$test =~ s/\n|\t//g;
# print FILE ( join( ',', map { $_->string_value() } @fields ), "\n");
print FILE "$test \n";
}
close (DATA);
close (FILE);
I'm converting a XML file into a .csv file. It works pretty well for
small XML files, but it doesn't work for big files ~150MB. My script
stops and gives me a memory problem message.
Anyone has any idea?
Here is the script that i'm using: Thanks,
#!/usr/bin/perl -w
## Remove commas
use warnings;
use strict;
use XML::XPath;
open (BLANK, "XML/Verizon.xml");
open (BLANK2, ">XML/Verizon2.xml");
## Align tags and values
my $blank = "";
while ($blank = <BLANK>) {
if ($blank =~ /^\s*$/) {
chomp($blank);
}
else {
$blank =~ s/,//g;
print BLANK2 $blank;
}
}
close (BLANK);
close (BLANK2);
iopen (DATA, "XML/Verizon2.xml");
open (FILE, ">import.csv");
my ($xp) = XML::XPath->new( join('', <DATA>) );
my(@records) = $xp->findnodes( '/TroubleTickets/TroubleTicket' );
my($firstTime) = 0;
foreach my $record ( @records ) {
my(@fields) = $xp->find( './child::*', $record )->get_nodelist();
unless ( $firstTime++ ) {
# print( join( ',', map { $_->getName() } @fields ), "\n");
print FILE ( join( ',', map { $_->getName() } @fields ), "\n");
}
# print( join( ',', map { $_->string_value() } @fields ), "\n");
my $test = join( ',', map { $_->string_value() } @fields );
$test =~ s/\n|\t//g;
# print FILE ( join( ',', map { $_->string_value() } @fields ), "\n");
print FILE "$test \n";
}
close (DATA);
close (FILE);