mdfaizy has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl # header modules ##################################################### +##################################################################### +########## ###################################################################### +##################################################################### +########## #read the input xml files for the TestSuite tags and its content open(SandBoxXML,$ARGV[0]) || die("sandbox xml file cannot be loaded;ch +eck for file name or existance"); my @sandboxxml = <SandBoxXML>; close(SandBoxXML); #chomp(@sandboxxml); for($i=0;$i<@sandboxxml;$i++) { $sandboxxml[$i] =~ s/^\s+//; #remove leading white spaces and tabs + from each line print $sandboxxml[$i]; #for testing } ###################################################################### +##################################################################### +########## #collecting the required data from the XML dump for($i=0;$i<@sandboxxml;$i++) { #print $sandboxxml[$i]; #for testing if($sandboxxml[$i] =~ /\<TestSuite\>/) { #$i++; #print $sandboxxml[$i]; #for testing while($sandboxxml[$i] !~ /\<\/TestSuite\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $tsnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $tsname=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<ATC\>/) { #$i++; while($sandboxxml[$i] !~ /\<\/ATC\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $atcnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $atcname=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Purpose /) { my $atcpurpose=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Requirement\>/) { #$i++; while($sandboxxml[$i] !~ /\<\/Requirement\>/) { if($sandboxxml[$i] =~ /\<ElementName\>/) { my $reqnumber=&readtagdata; #push(@data,$data.","); } if($sandboxxml[$i] =~ /\<Name\>/) { my $reqname=&readtagdata; #push(@data,$data.","); } push(@data, $tsnumber.",".$tsname.",".$atc +number.",".$atcname.",".$atcpurpose.",".$reqnumber.",".$reqname."\n") +; $i++; } } $i++; } } $i++; } } } ###################################################################### +##################################################################### +########## # making the output file open(OUTPUT, ">TestSuite.csv") || die("Cannot make the outpur file...G +OD knows for what reason"); #for testing print OUTPUT @data; #for testing close(OUTPUT); ###################################################################### +##################################################################### +########## #sub functions sub removespace { foreach(@sandboxxml) { $_ =~ s/^[ \t]+//; #remove leading white spaces and tabs from +each line chomp($_); #remove newline character from each line } } sub readtagdata { my @tmp0 = split(/\>/,$sandboxxml[$i]); my @tmp1 = split(/\</,$tmp0[1]); return $tmp1[0]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern match screwed up!!
by kennethk (Abbot) on Jan 22, 2015 at 00:51 UTC | |
|
Re: pattern match screwed up!!
by Anonymous Monk on Jan 21, 2015 at 23:14 UTC | |
|
Re: pattern match screwed up!! (junit xml)
by Anonymous Monk on Jan 22, 2015 at 00:22 UTC | |
by mdfaizy (Initiate) on Jan 22, 2015 at 08:38 UTC | |
by jfroebe (Parson) on Jan 22, 2015 at 14:03 UTC | |
|
Re: pattern match screwed up!!
by roboticus (Chancellor) on Jan 22, 2015 at 11:54 UTC |