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; }