I’m parsing an XML document and trying to create an array of hashes
using the following:
roomcats = Array.new
rmcategory = Hash.new
doc.xpath(’//RoomCategory’).each do |rc|
rmcategory[“id”]=rc[‘Id’]
rmcategory[‘sdesc’]=rc.xpath(’./Description’).text
rmcategory[‘ldesc’]= rc.xpath(’./RoomDescription’).text
roomcats.push rmcategory
end
However what I’m getting is an array of hashes with all elements of the
array equal to the last element. A bit of experimenting has shown that
each time the hash value changes through the loop the associated entry
in the Array is also changed. i.e. The array element is ‘pointing’ to
the hash rather than taking on separate values.
Please can someone tell me what I should do to achieve what I want.
Thanks
Purvez