want to fetch the data from xml file using more than one keyword

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pranjal9880
    New Member
    • Jun 2007
    • 5

    want to fetch the data from xml file using more than one keyword

    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]
    Last edited by miller; Jul 13 '07, 10:51 PM. Reason: Code Tag and ReFormatting
  • Pranjal9880
    New Member
    • Jun 2007
    • 5

    #2
    It looks like I had to mention Perl in my question.. I m doing XML parsing in Perl

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Greetings Pranjal,

      And welcome to TSDN.

      Parsing XML is a task that involves more knowledge of the XML specification rather than knowledge of Perl. Most of my parsing needs are solved purely through XML::Simple, as that module lets you immediately translate XML into a perl data structure.

      The only advice I can give you concerning other XML modules is to read their respective documentation. This isn't much help of course, but it's the most I have to offer on this subject.

      cpan XML::XPath

      - Miller

      Comment

      • Pranjal9880
        New Member
        • Jun 2007
        • 5

        #4
        Thanks Miller for reply...but if you can guide me through the input part for more than one keyword like using AND and OR operator like && and || in C/C++ by the command line as you can see in the first part of my code...and one more thing I wanted to ask was how can I specify input directly from the command line...I know there are some command line options to do it but not able to figure out how can i use them...

        Thanks

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          adding input/arguments on the command line:

          Code:
          perl yourscript.pl arg1 arg2 arg3
          getting the arguments into your perl program:

          Code:
          #!/usr/bin/perl
          my ($arg1,$arg2,$arg3) = @ARGVS;
          of course that is a very simple example. You can also use one of the Getopt modules that comes with perl:

          Comment

          Working...