in reply to XPath query issue...

I don't know how XML::XPath (mis)handles namespaces, so I'll assume no fixes are needed in that area.

sub to_xpath_str_literal { my ($s) = @_; return qq{"$s"} if $s !~ /"/; return qq{'$s'} if $s !~ /'/; $s =~ s/'/',"'",'/g; return qq{concat('$s')}; } my $cve_id_lit = to_xpath_str_literal($cve_id); for my $entry ($xp->findnodes("/nvd/entry[\@id=$cve_id_lit]")) { my ($metrics) = $entry->findnodes('vuln:cvss/cvss:base_metrics'); my $av = $metrics->find('cvss:access-vector'); my $ac = $metrics->find('cvss:access-complexity'); ... }

Three fixes:

Replies are listed 'Best First'.
Re^2: XPath query issue...
by spstansbury (Monk) on Sep 02, 2009 at 19:54 UTC

    Thank you!

    That worked as I had intended, but could not make happen...

    Question: The process is very slow. The source files range from 12Mb to 30Mb. Is there another approach that would search through the file faster?

    Thanks again for your help...

    Scott...

      I don't know how fast a parser you are using. XML::LibXML is extremely fast.

      Each XPath is surely parsed repeatedly. You could avoid using XPath inside the loop.

      Each find will search through all of the child nodes, but since it seems you want most of the child nodes. You could replace the XPath with a loop that populates a hash.