views:

33

answers:

1

I have a ROXML object that looks like:

class Activity
  include ROXML
  xml_accessor :id
end

If I have an array of these objects and call .to_xml on the array, I receive an empty xml collection:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<activities type=\"array\">\n</activities>\n"

Any idea why or how to fix this?

I'm running Rails 2.3.5 with the newest version of ROXML.

A: 

Similar question: http://stackoverflow.com/questions/2844106/ruby-roxml-how-to-get-an-array-to-render-its-xml. Look there for details.

It seems that it is not possible to convert an array using ROXML. One way to solve this is to define new class for collection:

class Activities
  include ROXML
  def initialize(activities) 
    @activities = activities 
  end
  xml_reader :activities, :as => [Activity]
end

And use:

Activities.new(activities).to_xml
Voyta
Interesting idea. I'll try that out. Cheers.
findchris