first level section no: 1.1 (two digits)
second level section no: 1.1.1 (3 digits)
third level section no: 1.1.1.1 (4 digits)
fourth level section no: 1.1.1.1.(i) (5 digits)
fifth level section no: 1.1.1.1.(i).(a) (6 digits)
####
$q ='1.1
sfasfasdfadsfsdaf
1.1.1
sahfjsahdfasddfj
1.1.2
sahfjsahdfasddfj
1.1.2.1
sahfjsahdfasddfj
1.1.2.2
safksajdklfasd
1.1.3
sahfjsahdfasddfj
1.2
sfasfasdfadsfsdaf
........';
####
my $nstr = $str;
$strnew =~ s/<(hsp|top\-border|bottom\-border|link locator|cp type)([^>]*)>/<$1$2\/>/gsi;
$strnew=~s/.*<\/bm>//gsi;
$strnew=~s/(&[^\s&;<>\n]+;)/'a' x length($1)/egsi;
#print ERR $strnew;
$strnew=~s/(.*)(
{ "sec" => sub {$newl=$_[0]->parser->current_line,$newc=$_[0]->parser->current_column, $_[1]->set_att(linenum=>$newl,colnum=>$newc),return $_[0]}
}
);
$t1->parse($strnew);
$strnew=$t1->sprint;
my $t= new XML::Twig(
twig_handlers =>
{
"sec"=>\&process_sec
},
PrettyPrint=>"none");
$t->parse($strnew);
#$strnew=~s/]*)>\n*(?!(<\/no>.*))<\/no>/$2<\/no>/gsi;
#print ERR $strnew."\n";
$strnew=$t->sprint("art");
my (%ntor,%ntoa);
%ntor=('1'=>'(i)','2'=>'(ii)','3'=>'(iii)','4'=>'(iv)','5'=>'(v)','6'=>'(vi)','7'=>'(vii)','8'=>'(viii)','9'=>'(ix)','10'=>'(x)','11'=>'(xi)','12'=>'(xii)');
%ntoa=('1'=>'(a)','2'=>'(b)','3'=>'(c)','4'=>'(d)','5'=>'(e)','6'=>'(f)','7'=>'(g)','8'=>'(h)','9'=>'(i)','10'=>'(j)');
my $p1 = new XML::Parser(Style => 'Subs');
$p1->parse($strnew);
my @s;
sub sec
{
my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k)=@_;
$no++;
#print $j."\n";
my $tf=$no;
my (@val)=map{$#s=--$_; $s[$_]++; @s}$tf;
local $"='.';
my @val1=@val;
if (scalar(@val) > 3)
{
$val1[3]=$ntor{$val[3]};
$val1[4]=$ntoa{$val[4]} if (scalar(@val)>4);
}
my $tp="@val1";
#print $aid_new.".".$tp."\n";
if ($aid_new1 =~ /^\d{2}$/)
{
if ($j ne "$aid_new.$tp")
{
print ERR "\n\n WARNING :Line ".($h + $lineno) ." Col ". (++$d)."\n\tCheck content inside the tag. The value may be $aid_new.$tp";
}
}
if ($aid_new1 =~ /^\d$/)
{
if ($j ne "$aid_news.$tp")
{
print ERR "\n\n WARNING :Line ".($h + $lineno) ." Col ". (++$d)."\n\tCheck content inside the tag. The value may be $aid_new.$tp";
}
}
my ($atts)=$j=~s/\.//gsi;
$atts-=1;
if ($no != $atts)
{
#print ERR "Check section Opening at line ", $h + $lineno," and column $d\n";
print ERR "\n\n WARNING :Line ".($h + $lineno)." Col ". (++$d)."\n\tCheck section Opening";
}
#print $no."\n";
}
sub sec_
{
my ($a,$b)=@_;
$no--;
#print $no."\n";
}
sub process_sec
{
my ($a,$b)=@_;
my $p=$b->first_child_text("no");
#print $p."\n";
$b->set_att(val=>$p);
#$b->sprint;
return $b;
}