Hi all
I am trying to parse the xml file using perl in which I am succeeded , I am able to fetch the data from the xml file by using one keyword. Now I want to do it using more than one keyword. It should work like if I give more than one keyword then it should not give me the redundant data..If data is same for more than one keyword then it should show it only once..and here is the code I have so far to search using one keyword..
[CODE=perl]
print "Enter the keyword:";
$givenKey = <STDIN>;
chop $givenKey;
use XML::XPath;
$file = 'test.html';
open(fd,">$file ");
print fd "<html><bod y>";
my $file = 'all_testsuites .xml';
my $xp = XML::XPath->new(filename=> $file);
my $nodeset = $xp->find('//testcase');
my $count=1;
for ($i = 1; $i <= $nodeset->size; $i++) {
$node = $nodeset->get_node($i) ;
print fd "\n";
foreach my $key ($xp->find('./keywords/keyword/@name',$node)) {
for($j = 1; $j <= $key->size; $j++) {
$nodeChild = $key->get_node($j) ;
$keyword = $nodeChild->getData;
if($keyword eq $givenKey) {
print fd "Test Case:";
print fd $count;
$count = $count +1;
print fd map($_->string_value,$ node);
print fd "<br>";
print fd "<br>";
}
}
}
}
print fd "Total Test cases are ";
print fd $count -1;
print fd "</html></body>";
close(fd);
[/CODE]
I am trying to parse the xml file using perl in which I am succeeded , I am able to fetch the data from the xml file by using one keyword. Now I want to do it using more than one keyword. It should work like if I give more than one keyword then it should not give me the redundant data..If data is same for more than one keyword then it should show it only once..and here is the code I have so far to search using one keyword..
[CODE=perl]
print "Enter the keyword:";
$givenKey = <STDIN>;
chop $givenKey;
use XML::XPath;
$file = 'test.html';
open(fd,">$file ");
print fd "<html><bod y>";
my $file = 'all_testsuites .xml';
my $xp = XML::XPath->new(filename=> $file);
my $nodeset = $xp->find('//testcase');
my $count=1;
for ($i = 1; $i <= $nodeset->size; $i++) {
$node = $nodeset->get_node($i) ;
print fd "\n";
foreach my $key ($xp->find('./keywords/keyword/@name',$node)) {
for($j = 1; $j <= $key->size; $j++) {
$nodeChild = $key->get_node($j) ;
$keyword = $nodeChild->getData;
if($keyword eq $givenKey) {
print fd "Test Case:";
print fd $count;
$count = $count +1;
print fd map($_->string_value,$ node);
print fd "<br>";
print fd "<br>";
}
}
}
}
print fd "Total Test cases are ";
print fd $count -1;
print fd "</html></body>";
close(fd);
[/CODE]
Comment