Read/Write file, break lines at 256 (or more) but NOT elements

Charlie Hanpru <[email protected]> Thu, 17 Mar 2011 08:55:06 -0400
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
 
Hi,
 
I have Perl script that reads in a xml file. Adds carriage returns in fron of specific elements then write the results to a TMP file. The problem I am having is if there is a tag with multiple attributes it will get broken in the middle which I can't have. How do I break the lines at 256 characters (or more) but NOT a tag? I'm really stumped on this one. Below is my code.
 
#!/usr/local/bin/perl
require 5.000;
use Env;
use Cwd;
use File::Basename;
use Text::Wrap qw(wrap $columns $huge);
$columns = 256;
$huge = "die";
my $infile = $ARGV[0];
open(FILEREAD, "$infile.xml");
 open(FILEWRITE, "> $infile.temp");
   $i=1;
  while (<FILEREAD>)
  {
   chomp $_;
   
   $_ =~ s/<\?xml/\n[kl]<\?xml/ig;
   $_ =~ s/<!DOCTYPE/\n[kl]<!DOCTYPE/ig;
   print FILEWRITE wrap("", "", $_), "\n";
   $i++;
  }
 close FILEWRITE;
close FILEREAD;

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs