Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created December 5, 2011 19:01
Show Gist options
  • Save pcarrier/1434790 to your computer and use it in GitHub Desktop.
Save pcarrier/1434790 to your computer and use it in GitHub Desktop.
require 'nokogiri'
doc = Nokogiri::XML open 'oval-definitions-2010.xml'
doc.css('definition[class="vulnerability"]').collect do |v|
references = v.css('reference').collect {|v| v['ref_id']}.grep /^CVE/
final_criteria = v.css('criterion[test_ref]').collect {|c| c['test_ref']}
next Hash[
final_criteria.collect{|c| doc.css "*[id='#{c}']"}.collect do |t|
obj_ref_nodes = t.css('*[object_ref]')
next unless obj_ref_nodes.first
obj_ref = obj_ref_nodes.first['object_ref']
state_ref_nodes = t.css('*[state_ref]')
next unless state_ref_nodes.first
state_ref = state_ref_nodes.first['state_ref']
obj = doc.css("*[id='#{obj_ref}']").first
state = doc.css("*[id='#{state_ref}']").first
next unless obj.name == 'dpkginfo_object'
next [obj.content.strip, state.content.strip]
end
end]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment