views:

194

answers:

2

I am trying to use xml builder without explicit definition of elements. This is useful when the required elements are variant.

How can I accomplish something similar to the following?

 xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
 for col in [:customer, :name, :address, :city, :street, :postal_code]
   eval("xml.#{col.to_s.upcase}(#{self[col]})")
 end

This code obviously does not work if there is a ' or " in self[col]. I would also prefer not to use eval. I have already tried:

xml.send(col.to_s.upcase, self[col]
A: 
xml.tag!(element_name, element_value)
Joseph Rodriguez
+2  A: 
xml.tag!(col.to_s_upcase, self[col])
MattMcKnight