#!/usr/bin/perl
use strict;
use warnings;
my $tag;
my $output;
my $fh;
my $deletestrings;
#open DATA,"$ARGV[0]";
while (<DATA>) {
chomp;
s/[\cA-\cZ]//g; # To remove control characters
#To delete the lines which has {IT} and any lines between {IT} and {SO
+URCETAG}
if (/\{IT\}/ .. /^\{SOURCETAG\}/) {
unless (/^\{(IT|SOURCETAG)\}/) {
$deletestrings = $_;
$_ = '' if index( $_, "$deletestrings" ) >= 0;
}
}
s/[\\|<]$//g;
s/^[\\|<]//g;
s/<//g;
s/^\s+//g;
s/\s+$//g;
if(/^{(.*)}$/) { # match {METATAG} line
$fh = output($output, $tag, $fh);
$output = "";
$tag = $1;
} else { # not a {TAG} line
next unless($tag);
next if(/^\s*$/);
s/\\//g;
$output .= ($output) ? " $_" : "<$tag>$_";
}
}
$fh = output($output, $tag, $fh);
if($fh) {
print $fh "</ROOT>\n";
close($fh);
}
exit(0);
sub output {
my ($output, $tag, $fh) = @_;
if($output) {
if($output =~ m/<SOURCETAG>(.*)/) {
if($fh) {
print $fh "</ROOT>\n";
close($fh);
}
open($fh, '>', "$1.xml") or die "$1.xml: $!";
print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RO
+OT>\n";
}
print $fh "$output</$tag>\n";
}
return($fh);
}
__DATA__
^C^D^V^V^A exit 0543 961017 N S 9702050900 00000000^B{IT}
N
{SOURCETAG}
9702050900
{ACCESSION}
000000
{DATE}
961017
{TDATE}
Thursday, October 17, 1996
{PUBLICATION}
EXITO
{EDITION}
Exito
{SECTION}
SALUD FAMILIAR
{PAGE}
22
{SOURCE}
Por Nahyr Acosta. Colaboradora de ¡Exito!
{COLUMN}
Nuestro hijos.
{HEADLINE}
EVITE LA ENFERMEDAD PERIODONTAL< AS
{LEAD}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ Cuando hace casi
+ dos años visité a mi dentista para hacerme un chequeo
dental , me encontré ante un problema que podÃa terminar con mi dent
+adura.
Siempre tuve unos dientes sanos y jamás se me ocurrió pensar que pod
+Ãa perder
mis piezas si no tomaba acción inmediata. Me puse en manos del denti
+sta y
empezamos a trabajar en mis encÃas.<
This code creates a xml output.
But for {LEAD} it doesnot creates the proper tag.
For the file when I pass the input file as an command line argument,
The output is seen as below.
<SECTION>SALUD FAMILIAR</SECTION>
<PAGE>22</PAGE>
<SOURCE>Por Nahyr Acosta. Colaboradora de ¡Exito!</SOURCE>
<COLUMN>Nuestro hijos.</COLUMN>
+ AS</HEADLINE>
<LEAD>Cuando hace casi dos años visité a mi dentista para hacerme un
+ chequeo dental , me encontré ante un problema que podÃa terminar c
+on mi dentadura. Siempre tuve unos dientes sanos y jamás se me ocurr
+ió pensar que podÃa perder mis piezas si no tomaba acción inmedia
+ta. Me puse en manos del dentista y empezamos a trabajar en mis encÃ
+as. La descomposición de la comida, la saliva y las bacterias que h
+ay en la boca producen una sustancia llamada placa, que se adhiere a
+la superficie de los dientes y, si no se limpia diariamente, irrita l
+as encÃas y se endurecen, formando el sarro. Esta sustancia, a su ve
+z, se adhiere cada vez más, inflamando las encÃas y produciendo bol
+sas que se llenan con colonias de bacterias. Estas son las que con el
+ tiempo, causan la enfermedad periodontal. Las bacterias también pro
+ducen una sustancia llamada toxina, la cual destruye el hueso.</LEAD>
For {LEAD} it creates the tag but not for HEADLINE |