分类: 系统运维
2012-12-20 16:28:04
use XML::XPath;
use XML::XPath::XMLParser;
use File::Find;
use File::Find::Rule;
my $mainPath="D:/09_install/BO/metadata/system";
my @files = File::Find::Rule->file()
->name( '*.xml' )
->in($mainPath); #xml文件数组放入数组中
sub exefile
{
my (@args)=@_;
#my $xp = XML::XPath->new(filename => 'BB_BILL_CHARGE_GMDB.bo.xml');
my $xp = XML::XPath->new(filename => @args[0]);
#需要判断bo.xml中有几个BoSchema,目前只处理xml中只有一个BoSchema的xml
#
#--------------------------------------------------------------------------
my $nodeset = $xp->find('/BoDAF/BoSchema/*'); # find all paragraphs
my @coms; #定义一个数组
foreach my $node ($nodeset->get_nodelist) {
# print "FOUND\n\n",
# XML::XPath::XMLParser::as_string($node), "\n"; #输出nodelist中的列表
my $href1 = $node->getAttributeNode ("name");
#print $href1->getValue . "\n"; #打印字段列表
#bo字段,存入数组
push(@coms,lc($href1->getValue));
}
#print @coms[1] . "\n"; #打印数组中第一个值
#print @coms,"\n"; #打印数组
#print $#coms . "\n"; #打印数组的大小,包含0
#print @coms[$#coms] . "\n"; #打印数组中最后一个元素
print $#coms+1 ,"个字段。\n"; #打印数组的实际大小
#-----------------获取BoNamingSql中的sql---------------------------------------------------------
my $nodeset = $xp->find('//Context');
my @fields;
foreach my $node ($nodeset->get_nodelist) {
# print "FOUND\n\n", lc(XML::XPath::XMLParser::as_string($node)),"\n"; #输出nodelist中的列表
if( lc(XML::XPath::XMLParser::as_string($node)) =~ m/select/)
{
my $abc=lc(XML::XPath::XMLParser::as_string($node));
#-------------
if( grep(/\*/,$abc) != 1 && grep(/delete/,$abc) != 1 )
{
#bo字段,存入数组
push(@fields,$abc);
}
#-------------
}
}
print $#fields+1,"个select namesql。\n";
#——————————————————————————————————
#增加判断bo数组是否为0,namesql是否为0
if( ($#coms+1) >= 1 && ($#fields+1) >= 1 )
{
for($y=0;$y < ($#coms+1);$y++)
{
for($a=0;$a < ($#fields+1);$a++)
{
my $count=grep(]);
#my $count=grep();
if($count==0)
{
open(OUTFILE, ">>outfile"); #写入到文件
print OUTFILE ("\n-------------------------------------------------------------------\n". @args[0] ."\n");
print OUTFILE (@coms[$y]," >>----在下面语句中缺少字段:--->>\n",@fields[$a],"\n");
}
#open(OUTFILE, ">>outfile");
#print OUTFILE ($count,"\n");
};
};
}
#——————————————————————————————————
#-----------------获取BoNamingSql中的sql-end--------------------------------------------------------
}
# 写for循环,处理 @files 中的xml文件
for($s=0;$s < ($#files+1);$s++)
##for($s=0;$s < 1;$s++)
{
#配置一些文件不读
#——————————————————————————————————
my @ifreadfile=("EventPropertyGroupDef.xml");
my $IRFcount=grep(]);
if($IRFcount != 1)
{
#exefile('D:\09_install\BO\metadata\system\Billing\BB_RUL_SAMPBILL_OBJ.bo.xml');
exefile(@files[$s]);
}
#——————————————————————————————————
}