473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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..

Expand|Select|Wrap|Line Numbers
  1. print "Enter the keyword:";
  2. $givenKey = <STDIN>;
  3. chop $givenKey;
  4. use XML::XPath;
  5.  
  6. $file = 'test.html';
  7. open(fd,">$file");
  8. print fd "<html><body>";
  9.  
  10. my $file = 'all_testsuites.xml';
  11. my $xp = XML::XPath->new(filename=>$file);
  12. my $nodeset = $xp->find('//testcase');
  13. my $count=1;
  14.  
  15. for ($i = 1; $i <= $nodeset->size; $i++) {
  16.     $node = $nodeset->get_node($i);
  17.     print fd "\n";
  18.  
  19.     foreach my $key ($xp->find('./keywords/keyword/@name',$node)) {
  20.         for($j = 1; $j <= $key->size; $j++) {
  21.             $nodeChild = $key->get_node($j);
  22.             $keyword = $nodeChild->getData;
  23.  
  24.             if($keyword eq $givenKey) {
  25.                 print fd "Test Case:";
  26.                 print fd $count;
  27.                 $count = $count +1;
  28.  
  29.                 print fd map($_->string_value,$node);
  30.                 print fd "<br>";
  31.                 print fd "<br>";
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. print fd "Total Test cases are ";
  38. print fd $count -1;
  39. print fd "</html></body>";
  40. close(fd);
  41.  
Jul 13 '07 #1
4 2328
It looks like I had to mention Perl in my question.. I m doing XML parsing in Perl
Jul 16 '07 #2
miller
1,089 Expert 1GB
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
Jul 16 '07 #3
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
Jul 17 '07 #4
KevinADC
4,059 Expert 2GB
adding input/arguments on the command line:

Expand|Select|Wrap|Line Numbers
  1. perl yourscript.pl arg1 arg2 arg3
getting the arguments into your perl program:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. 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:

http://perldoc.perl.org/index-modules-G.html
Jul 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
1
by: Agoston Bejo | last post by:
The problem is as follows: I have a stored proc. that returns a types.ref_cursor (where types.ref_cursor is defined as 'ref cursor'): PROCEDURE P(c OUT TYPES.ref_cursor); The returned cursor has...
2
by: Joakim Olesen | last post by:
Hi I have a table with a BLOB column which contains bmp images. I'm unsuccessfully trying to fetch one of these images and saving it as a file. The result is a file with a size of 12Kb, but it's...
2
by: Michel Esber | last post by:
System scenario: Linux DB2 Workgroup Server V7 FixPack 13. I have a java application (JDBC v2 driver) that reads into memory a considerable amount of data (100k-300k rows), summarizes the...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
10
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The...
15
by: dataguy | last post by:
I am trying to insert into a temporary table but only the first n number of rows. I thought I could use the combination of insert into and fect first row command ,but it won't work. Does anyone...
17
by: broughcut | last post by:
Is it possible to fetch a specific div from a source html document using XMLHttpRequest, rather than fetching the entire file? I was going to use Ajax on mouseover but keep the normal link...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.