ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Can I use a variable in an xpath?
by Amanda Hubbard other posts by this author
May 25 2006 1:37PM messages near this date
view in the new Beta List Site
RE: case insensitive searching | Re: Can I use a variable in an xpath?
& XSLT I'm trying to find a value in an XML document using XPATH.  I want to use a variable 
that contains the path because I will be looping through several paths and passing them to a
 method.  Is this valid?
 
##$browser is an LWP::UserAgent object
my $URL = "$protocol\://$host:$port/sdk/$parent?ip=$ip";
my $response = $browser-> get($URL);

$searchPath="chassis/ramMemory/size";
my $parser = XML::XPath::XMLParser-> new(xml => $response->content);
my $root_node = $parser-> parse;
my $xp = XML::XPath-> new(context => $root_node);

###Is there a way to make the following work?  
my $nodeset=$xp-> find('$searchPath[@value]');
 
###Rather than:
my $nodeset=$xp-> find('chassis/ramMemory/size[@value]');

The errror I am getting is:
Can't call method "isa" on an undefined value at C:/Perl/site/lib/XML/XPath/Expr.pm line 142
.
 
Any pointers would be greatly appreciated.
 
Thanks,
Amanda
 
Thread:
Amanda Hubbard
Grant McLean
A. Pagaltzis
Grant McLean
Shlomi Fish
Mark - BLS CTR Thomas

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved