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. |
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 ...
|
|||||||
| PERL PERL Scripts - Tips, Tricks, Issues, Latest News, PERL Resource and PERL related topics can be discussed in this forum. |
![]() |
| LinkBack | Thread Tools | Display Modes |
|
|||
|
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 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";
}
}
Code:
if ($processname eq "myprocess1") {
print "processinputfile=$processinputfile\n";
}
select process_input_file from child.xml where processname="myprocess1" Thanks Sajith |
| Sponsored Links |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
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 |