From: Rick DeNatale Date: 2008-07-01T01:48:08+09:00 Subject: Re: is it possible to create a hash dynamically? ------=_Part_32933_27540842.1214844651410 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jun 30, 2008 at 12:32 PM, aidy wrote: > Hi, > > I am trying to build a dynamic hash map > > > def extract(xml, path) > require 'rexml/document' > xml = xml.to_s.gsub("utf-16", "utf-8") > doc = REXML::Document.new(xml) > doc.root.each_element(path) do |element| > element.each_element do |node| > puts "name: #{node.name} text: #{node.text}" > @xml_data = {node.name => node.text} > end > end > return @xml_data > end > > > However, the @xml_data is always returning 1 element def extract(xml, path) require 'rexml/document' xml = xml.to_s.gsub("utf-16", "utf-8") doc = REXML::Document.new(xml) xml_data = {} doc.root.each_element(path) do |element| element.each_element do |node| puts "name: #{node.name} text: #{node.text}" xml_data[node.name] = node.text end end return xml_data end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ------=_Part_32933_27540842.1214844651410--