Robert Dober wrote: > On Tue, Aug 24, 2010 at 6:33 AM, Shyam Krishna Khadka > <shyamkkhadka / gmail.com> wrote: > > Hmm I have to do some guessing here > > the base idea is that you need hashes as elements, thus parting from > the hypothetical problem > > [ :a, 42, "a"].to_xml > RuntimeError: Not all elements respond to to_xml > > you can do something like this > > [ :a, 42, "xxx"].map{|x| { :name => x } }.to_xml > => "<?xml version="1.0" encoding="UTF-8"?>\n<records type="array">\n > <record>\n <name type="symbol">a</name>\n </record>\n <record>\n > <name type="integer">42</name>\n </record>\n <record>\n > <name>xxx</name>\n </record>\n</records>\n" > > If you still have problems it would be helpful to post some code, one > would need to look into the ary > > HTH > R. Thanks for your reply. But I am afraid that it works only in rails console, not in irb console. This is because to_xml method is defined inside ActiveSupport of rails. But I want pure ruby code to convert to xml. Actually in my case, array is the collection of objects. And object is basically collection of hashes. Finally I made it own using REXML. For reference see : http://www.ibm.com/developerworks/xml/tutorials/x-rubyonrailsxml/section4.html -- Posted via http://www.ruby-forum.com/.