How to create XML

hi

I wanna crate XML file in this format.

<rsp status_code="0" status_message="Success">   <daily_counts>      <count date="20100415T00:00:00">214</count>      <count date="20100409T00:00:00">205</count>      <count date="20100410T00:00:00">14</count>      <count date="20100411T00:00:00">44</count>      <count date="20100402T00:00:00">21</count>      <count date="20100422T00:00:00">241</count>      <count date="2010041T00:00:00">14</count>   </daily_counts> </rsp>

when I user render :xml => @service

then it pick all the data from the table and show. But the format is not what I want.

my table name is service-enquiries.

<service-enquiries type="array"> <service-enquiry>    <user_id type="NilClass">6</user_id>    <date type="NilClass">2009-06-22</date> </service-enquiry> </service-enquiries>

How I change the format?

user builder to build your xml template and render the template

create a file service.xml.builder in the view directory for that controller

then

xml.rsp(:status_code => “0”, :status_message=> “Success”) xml.daily_counts @services.each do |service| xml.count(service.code,:date=> service.date) end end

then render => “services” there you have it

<daily_counts> 214</

 <count date="20100409T00:00:00">205</count>

 <count date="20100410T00:00:00">14</count>

 <count date="20100411T00:00:00">44</count>

 <count date="20100402T00:00:00">21</count>

 <count date="20100422T00:00:00">241</count>

 <count date="2010041T00:00:00">14</count>

</daily_counts>

radhames brito wrote:

user builder to build your xml template and render the template

create a file service.xml.builder in the view directory for that controller

then

xml.rsp(:status_code => "0", :status_message=> "Success")   xml.daily_counts     @services.each do |service|         xml.count(service.code,:date=> service.date)   end end

then render => "services" there you have it

<rsp status_code="0" status_message="Success"> <daily_counts>     <count date="20100415T00:00:00">214</ >     <count date="20100409T00:00:00">205</count>     <count date="20100410T00:00:00">14</count>     <count date="20100411T00:00:00">44</count>     <count date="20100402T00:00:00">21</count>     <count date="20100422T00:00:00">241</count>     <count date="2010041T00:00:00">14</count> </daily_counts> </rsp>

Hi radhames brito

thanx for your support. Can you give the link from where I learn more. How to create XML.

what you tell me above is very nice. But I wanna know how it is working.

so pls if possible give me the link.

http://api.rubyonrails.org/classes/ActionView/Base.html

radhames brito wrote:

ActionView::Base

thank u radhames brito. If I get any problem in this. I'll again disturb u.

oh please do.