Topic: Searching XML using Nokogiri
Here is an extract of the xml file I am working with:
<?xml version="1.0" encoding="UTF-8" ?>
<report Title="my report" computer_name="my computer">
<software Title="Software">
<page Title="Security">
<item Property="Windows Firewall">
<item Property="Program" Value="c:\windows\system32\firewall.cpl" />
<item Property="Version" Value="5.1.2600"
<item Property="Antivirus" />
<item Property="AntiSpyware" />I need to iterate through the nodes and end up with objects as follows:
SecuritySoftware.create!(:name => 'Windows Firewall', :program => 'c:\windows\system32\firewall.cpl', :version => '5.1.2600')
SecuritySoftware.create!(:name => 'Antivirus')
SecuritySoftware.create!(:name => 'AntiSpyware')
So far I have...
doc = Nokogiri::XML(File.open('public/my_xml_file.xml'))
doc.search([Title="Security"])I just can't figure out how to loop through the child nodes/elements and retrieve their 'value'.