I have a XML document that looks something like this:
<permit>
<id>1</id>
<inspection>
<amount>100</amount>
<type>pool</type>
</inspection>
<inspection>
<amount>400</amount>
<type>pluminbing</type>
</inspection>
</permit>
<permit>
<id>2</id>
<inspection>
<amount>1500</amount>
<type>roof</type>
</inspection>
<inspection>
<amount>1700</amount>
<type>building</type>
</inspection>
</permit>
I know I can loop through the permits and out the id like so:
REXML::XPath.each(doc, '//permit') do |permit|
permit_hash = {:id => permit.elements['id'].text}
end
But I can't seem to loop through each permit's inspections and finally get an array output such as:
permits = [{:id => 1, :inspections => [{:amount => 100, :type => 'pool'}, {:amount => 400, :type => 'plumbing'}]}, {:id => 2, :inspections => [{:amount => 1500, :type => 'roof'}, {:amount => 1700, :type => 'building'}]}]
Seems like everything I try I get all inspections rather than just the inspections for each permit.
Suggestions?