in reply to XPath query issue...

I don't believe you:

use strict; ... my $cve_id = 'CVE-2008-3763'; my $query = "/nvd/entry[@id = $cve_id]";

This code gives me:

Possible unintended interpolation of @id in string at tmp.pl line 3. Global symbol "@id" requires explicit package name at tmp.pl line 3. Execution of tmp.pl aborted due to compilation errors.

So you're either not using strict and warnings, or you're not posting the code you're running. Either way, I don't see how you expect us to help you, if you're not forthcoming about what you're actually doing.

Replies are listed 'Best First'.
Re^2: XPath query issue...
by bluescreen (Friar) on Sep 03, 2009 at 00:27 UTC
    Did you try changing
    my $query = "/nvd/entry[@id = $cve_id]";
    to:
    my $query = "/nvd/entry[@id = '$cve_id']";
    And regarding a better parser it depends on how much information you want to read, XML::LibXML use a DOM Parser which builds a tree model for the document and then you can access that tree, the other standard parsing model is SAX which is based on events, and that is the fastest approach. Of course SAX parsers are much more complicated but in my experience it resulted on an improvement of 500%.
Re^2: XPath query issue...
by spstansbury (Monk) on Sep 02, 2009 at 18:21 UTC

    Umm, that's the point - the code doesn't work - if it worked I wouldn't be asking how to fix it..

      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)) { }

        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

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