Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: XPath query issue...

by spstansbury (Monk)
on Sep 02, 2009 at 18:31 UTC ( [id://792988]=note: print w/replies, xml ) Need Help??


in reply to Re^2: XPath query issue...
in thread XPath query issue...

The issue is just that - the @ is being interpreted as a global symbol and it should behave as a XPATH symbol signifying the attribute.

my $query = "/nvd/entry[@id = $cve_id]"; my $xp = XML::XPath-> new(filename => "$data_file"); foreach my $cve_entry ($xp->findnodes($query)) { }

Replies are listed 'Best First'.
Re^4: XPath query issue...
by derby (Abbot) on Sep 02, 2009 at 19:11 UTC

    You need to escape the @ somehow so perl does not try to interpolate it:

    my $query = '/nvd/entry[@id = ' . $cve_id . ']';
    or
    my $query = "/nvd/entry[\@id = $cve_id]";

    -derby
Re^4: XPath query issue...
by Corion (Patriarch) on Sep 02, 2009 at 19:21 UTC

    ... which is what both use strict; and use warnings; would have told you, if you had used them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://792988]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-16 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found