Question: I need to create an XML file output like:

```
<data>
    <hour>0</hour>
    <count>8</count>
</data>
.
.
<data>
    <hour>23</hour>
    <count>1</count>
</data>

```

I wrote the following code in my controller:

```
for @k in (0..23)
  @data.push(Datum.new(@k,@freq[@k]));
end

class Datum  
  def initialize(hour, count)  
    @hour = hour  
    @count = count  
  end  
end

render xml:@data

```

But the output comes out like:

```
    tweet-densities-controller-data type="array">
    <tweet-densities-controller-datum type="TweetDensitiesController::Datum">#
    TweetDensitiesController::Datum:0xacbddc4></tweet-densities-controller-datum>

```

Answer: 
You may want to take a look at builder: [Generating custom XML for your rails app](http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/)
What is happening here is that when you do `render :xml => @data` Rails is trying to convert `@data` (which is an Array) to its XML representation. This is not what you want in this case.

Define a `#to_xml` method on your Datum class and then you can do something like:

```
@data.map(&:to_xml).join("\n")

```

Which will call the `#to_xml` method for every object and then you'll concatenate them, separating each entry by a newline.

If you want well-structured XML data (doesn't seem like it from your example) then you should use something like Builder as suggested by jessecurry.