-1
  <test name="">
  <class name="48.">
  </class>
  </test>

The above entry comes in my file for around four times and I want to remove those entries from the file, so I'm using the following logic:

#!/usr/bin/perl
$count=0;
open (FILE, '/tmp/uday/testng-results.xml');
my@lines = <FILE>;
for(my $i=0;$i<$#lines;$i++)
{
    if($lines[$i] =~ /<test name="">/)
    {
        $count++;
    }
}
print "$count\n";
while($count!=0)
{
    open (FILE, '/tmp/uday/testng-results.xml');
    my  @lines = <FILE>;
    for(my $i=0;$i$#lines;$i++)
    {
        if($lines[$i] =~ /<test name="">/)
        {
            print "Start line number $i\n";
            $Start=$i;
            $End=$i+4;
            print "$End Line number End\n";
            system("sed -i '$Start,$End d' testng-results.xml");
        }
    }
    $count--;
} 

Is their any better way to do it?

4

1 回答 1

0

Using XML::XSH2, a wrapper around XML::LibXML:

open /tmp/uday/testng-results.xml ;
remove //test[@name=""][class[@name="48."]] ;
save :b ;
于 2013-07-25T13:17:41.623 回答