473,789 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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 2349
Pranjal9880
5 New Member
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 Recognized Expert Top Contributor
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
Pranjal9880
5 New Member
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 Recognized Expert Specialist
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
4453
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 part, the scripts were created with http://phpcodegenie.sourceforge.net/
2
3190
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 http://pydoc.org/2.3/imaplib.html as:: (typ, ) = <instance>.fetch(message_set, message_parts) In RFC 2060 it says: "The data items to be fetched can be either a single atom or a parenthesized list."
1
8653
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 a bunch of columns, but I only need a few of them. Anyway, with FETCH INTO I have to provide variables for every column. So I have to do this: var1 Type1; var2 Type2; ...
2
1608
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 not a valid BMP file (I can't view it in an image viewer). The image I try to fetch is quite small though, so the size (12Kb) is sensible. I've pasted my code below (and it doesn't throw any exception): using System;
2
2031
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 results and then deletes data from the DB. This is done hourly. According to my developer, the application opens a cursor and (fetch next) until the end. I have created an event monitor and the SQL sent to the DB is not poorly written (it uses the...
7
3537
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 performs MySQL queries to a database. These queries are performed at regular intervals. Basically it is looking for fields that match certain criterias. Such fields are not present at all time. When the program finds such field, it then takes
10
13237
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 fetch works as I would expect it to on the 2 rows, but then when I do my next fetch, the program ends abnormally. My next step is to check for sqlcode 100, as I would expect it to be, but my program never even gets to this step.
15
10873
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 know why? Any other suggestions other than writing a loop? This is in a db2 sql stored procedure that is called from another db2 sql stored proc.
17
3550
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 intact, so that if the user does not have javascript they can click the link as normal and this would take them to the new page, but if they have javascript (and ActiveX enabled I guess, in the case of IE) it would just fetch the appropriate div into...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.