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]

2 Answers 2

2
xml.tag!(col.to_s_upcase, self[col])
Sign up to request clarification or add additional context in comments.

Comments

0
xml.tag!(element_name, element_value)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.