title: Nokogiri conditional parsing
body: <p>I have some pretty unorganized XML (courtesy of a 3rd party application I'm using) that I need to parse.</p>
  
  <p>If the element <code>result/nvt/cve</code> has a value (besides 'NOCVE') then I need to save certain values.</p>
  
  <p>Some of the XML, with both 'NOCVE' and a CVE:</p>
  
  <pre><code>&lt;X&gt;
  &lt;result id="8791e80e-f254-479f-907e-e2667f57246b"&gt;
    &lt;nvt oid="1.3.6.1.4.1.25623.1.0.111038"&gt;
      &lt;cve&gt;NOCVE&lt;/cve&gt;
      .......
  &lt;/result&gt;
  
  &lt;result id="c1bf6c4e-1192-418a-bb2c-a3e3376dd42f"&gt;
    &lt;name&gt;Dropbear SSH CRLF Injection Vulnerability&lt;/name&gt;
    &lt;detection&gt;
      &lt;result id="1817a9ea-379f-41ad-9450-e2c1d6d73f9b"&gt;
        &lt;details&gt;
          &lt;detail&gt;
            &lt;name&gt;source_name&lt;/name&gt;
            &lt;value&gt;Dropbear SSH Detection&lt;/value&gt;
          &lt;/detail&gt;
        &lt;/details&gt;
      &lt;/result&gt;
    &lt;/detection&gt;
    &lt;host&gt;10.10.10.1&lt;/host&gt;
    &lt;port&gt;2222/tcp&lt;/port&gt;
    &lt;nvt oid="1.3.6.1.4.1.25623.1.0.807740"&gt;
      &lt;name&gt;Dropbear SSH CRLF Injection Vulnerability&lt;/name&gt;
      &lt;cve&gt;CVE-2016-3116&lt;/cve&gt;
    &lt;/nvt&gt;
  &lt;/result&gt;
  &lt;/X&gt;
  </code></pre>
  
  <p>In this case, the 2nd XML <code>result</code> element has <code>&lt;cve&gt;CVE-2016-3116&lt;/cve&gt;</code> whereas the first one has <code>&lt;cve&gt;NOCVE&lt;/cve&gt;</code>.</p>
  
  <p>I'm trying to search my document, determine if the <code>&lt;cve&gt;&lt;/cve&gt;</code> has a value other than <code>NOCVE</code> and then save various element text into variables for later use:</p>
  
  <pre><code>doc = File.open("results.xml") { |f| Nokogiri::XML(f) }
  
  root = doc.xpath("/X/get_results_response")
  
  root.xpath("//result").each do |result|
    if result.at_xpath("//nvt/cve").text != 'NOCVE'
      result_id = result.at_xpath("@id").value
      host = result.at_xpath("host").text rescue nil
      cve = result.at_xpath("//nvt/cve").text
      puts "#{result_id} #{host} - #{cve}"
    end
  end
  </code></pre>
  
  <p>However, I'm not getting any results!  I also realize this code my be totally inefficient, so if you have suggestions, please share!</p>