Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

perl program to query value of attribute1 where attribute2 equals something

This is a discussion on perl program to query value of attribute1 where attribute2 equals something within the PERL forums, part of the Web Development category; Hi, I have an xml file like the one below. child.xml Code: <?xml version="1.0" encoding="ISO-8859-1"?> <childroot> <childelement processname="myprocess1" process_input_file="${[//dir@mypath]}/myinputfile1.txt"></childelement> <childelement processname="myprocess2" process_input_file="${[//dir@mypath]}/myinputfile2.txt"></childelement> </childroot> I need to find out value of ...

Go Back   Geeks Talk > Web Development > PERL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

PERL PERL Scripts - Tips, Tricks, Issues, Latest News, PERL Resource and PERL related topics can be discussed in this forum.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-30-2009
Junior Member
 
Join Date: May 2008
Location: India
Posts: 26
Thanks: 1
Thanked 1 Time in 1 Post
sajithkutty is on a distinguished road
perl program to query value of attribute1 where attribute2 equals something

Hi,

I have an xml file like the one below.

child.xml
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<childroot>
    <childelement processname="myprocess1" process_input_file="${[//dir@mypath]}/myinputfile1.txt"></childelement>
    <childelement processname="myprocess2" process_input_file="${[//dir@mypath]}/myinputfile2.txt"></childelement>
</childroot>
I need to find out value of process_input_file where value of processname is "myprocess1".

I have the following code which does what i want but perhaps is not the best way of doing this.

Code:
#!/usr/bin/perl
use XML::XPath;
my $xp = XML::XPath->new(filename => 'c:/child.xml');
my $nodeset = $xp->find('//childroot/childelement');
foreach my $node ($nodeset->get_nodelist) {
  $processname = "".$node->find('@processname');
  $processinputfile = "".$node->find('@process_input_file');
  if ($processname eq "myprocess1") {
    print "processinputfile=$processinputfile\n";
  }
}
Is there a direct query for achieving what the following does?
Code:
  if ($processname eq "myprocess1") {
    print "processinputfile=$processinputfile\n";
  }
something like
select process_input_file from child.xml where processname="myprocess1"

Thanks
Sajith
Reply With Quote
Sponsored Links
Reply

  Geeks Talk > Web Development > PERL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
New with perl shrupeete PERL 3 07-30-2008 04:40 PM
Working with XML in Perl Lokesh M AJAX & XML 0 09-06-2007 11:29 AM
about PERL... psuresh1982 PERL 5 09-04-2007 11:04 PM
Differance between "==" & string.equals() Geek_Guest Java 4 07-26-2007 04:00 AM
Overriding equals for a subclass... psuresh1982 Java 0 07-17-2007 02:31 PM


All times are GMT -4. The time now is 01:14 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved