0

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]
Joseph Rodriguez
  • 1,135
  • 9
  • 14

2 Answers2

2
xml.tag!(col.to_s_upcase, self[col])
MattMcKnight
  • 8,185
  • 28
  • 35
0
xml.tag!(element_name, element_value)
Joseph Rodriguez
  • 1,135
  • 9
  • 14