chrismassey
Programmer
Hello,
I have a Perl script which divides a large XML files into smaller files. It works great, except if I view the XML file in notepad I can see that the initial tags haven't been placed on a new line.
It should look like this:
However, its being displayed as:
If I use \n to create a new line then its still displayed on the same line but with a tiny square in between which obviously represent the new line character.
How can I produce neat XML when viewed in notepad as a text file?
I have included my script below:
Thank you very much,
Chris
I have a Perl script which divides a large XML files into smaller files. It works great, except if I view the XML file in notepad I can see that the initial tags haven't been placed on a new line.
It should look like this:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<OUTER_TAG>
<FORM>
However, its being displayed as:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?><OUTER_TAG><FORM>
If I use \n to create a new line then its still displayed on the same line but with a tiny square in between which obviously represent the new line character.
How can I produce neat XML when viewed in notepad as a text file?
I have included my script below:
Code:
#! /usr/bin/perl
use strict;
use CGI ':standard';
print "Content-type: text/html\n\n";
my $outer_splitter = 'OUTER_TAG';
my $splitter = 'FORM';
my $xml_file = "xml_file.xml";
open (LOG,"<$xml_file") || die "Cannot Open: $xml_file";
my $count = 0;
my $files_counter = 1;
my $max_records = 1;
while (<LOG>){
if ($count == 0){
my $filename = 'File_'.$files_counter.'.xml';
open(LOG2,">$filename") || die "Cannot Open: $filename";
print "$filename >>> Created (XML)<br>";
my $filename_pdf = 'File_'.$files_counter.'.pdf';
open(LOG3,">$filename_pdf") || die "Cannot Open: $filename_pdf";
print "$filename_pdf >>> Created (PDF)<p>";
[COLOR=red]print LOG2 '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";[/color]
[COLOR=red]print LOG2 "<$outer_splitter>\n";[/color]
$count++;
}
if (grep /<\/$splitter>/, $_ ){
$count++;
}
print LOG2 $_;
if ($count == $max_records + 1){
print LOG2 "<\/$outer_splitter>";
$count = 0;
$files_counter++;
close(LOG2);
}
}
print "<b>Complete<b>";
Thank you very much,
Chris