Parsexml into ruby objects and save

yap_jp

New Member
I'm using happy mapper for object mapping in ruby , then parse the xml data in the .xml files i obtain from the api.I get a zip file in the api response and extract it to get 5-6 files with same xml format of data.The data in each file is around 2-3 mb.I want to save this data in files keeping in mind that i should be able to perform search operations over it.I don't want to use relational db rather would be looking to save the data in files. What should be the better approach to save the data which will be efficient enough for the later search operations to be performed on that data.\[code\]require 'json'require 'happymapper'file_contents = File.read('/home/GhostRider/x.xml') class Message include HappyMapper tag 'Message' element :color, String, :tag => 'Colour' element :bg_color, String, :tag => 'BgColour' end class Status include HappyMapper tag 'Status' element :text, String, :tag => 'Text' element :color, String, :tag => 'Colour' element :bg_color, String, :tag => 'BgColour' has_one :message, Message end class Line include HappyMapper tag 'Line' # if you put class in module you need tag element :name, String, :tag => 'Name' element :color, String, :tag => 'Colour' element :bg_color, String, :tag => 'BgColour' element :url, String, :tag => 'Url' has_one :status, Status end class Lines include HappyMapper tag 'Lines' # if you put class in module you need tag has_many :lines, Line enditem = Lines.parse(file_contents, :single => true)item.lines.each do |i| puts i.name, i.color, i.url, i.status.text, i.status.message.colorend\[/code\]I need to save this data obtained.
 
Back
Top