Read/Write XML file

--_cd277128-419a-4422-96b8-add6f5fb4dfd_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



Hi=2C

I can't seem to figure this out. I am reading in a xml file. Searching spec=
ific tags and adding a carriage return since data truncates. I'm breaking t=
he lines at 256 characters (could be more). The problem is that sometimes a=
tab will get broken which I can't have. How can I have the script break th=
e line either before or after the tag?

See below <link how it breaks.

ex.

<para>text text text text text text text text text text text text text text=
text text
text text text text text text text text text text text text text text text =
text <link var=3D"?"
var2=3D"?" var=3D"?"> text text </para>

Below is my script. What am I not doing right?



Syntax: perl test.pl input


#!/usr/local/bin/perl

require 5.000=3B

use Env=3B
use Cwd=3B
use File::Basename=3B
use Text::Wrap qw(wrap $columns $huge)=3B

$columns =3D 256=3B
$huge =3D "die"=3B

my $infile =3D $ARGV[0]=3B
open(FILEREAD=2C "$infile.xml")=3B
open(FILEWRITE=2C "> $infile.temp")=3B
$i=3D1=3B
while (<FILEREAD>)
{
chomp $_=3B

$_ =3D~ s/<\?xml/\n<\?xml/ig=3B
$_ =3D~ s/<!DOCTYPE/\n<!DOCTYPE/ig=3B

print FILEWRITE wrap(""=2C ""=2C $_)=2C "\n"=3B
$i++=3B
}
close FILEWRITE=3B
close FILEREAD=3B

=

--_cd277128-419a-4422-96b8-add6f5fb4dfd_--
killswi7ch1 [ Do, 17 März 2011 14:17 ] [ ID #2056727 ]
Perl » gmane.comp.lang.perl.beginners » Read/Write XML file

Vorheriges Thema: ip address substitution
Nächstes Thema: MRF-ERROR: Is a directory