# Output XML to File

**URL:** <https://www.ruby-forum.com/t/output-xml-to-file/226046>\
**Category:** Rails\
**Created:** [August 4, 2009, 11:42pm UTC](https://www.ruby-forum.com/t/output-xml-to-file/226046 "2009-08-04T23:42:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 4, 2009, 11:42pm UTC](https://www.ruby-forum.com/t/output-xml-to-file/226046/1 "2009-08-04T23:42:38Z")

</div>

I am trying to read some information based on a user id, then search the  
database for the needed info and build an XML file. Everything seems to  
be working fine; I read the info, I create the xml and even spit “stuff”  
out to file. The issue is that the “stuff” I am writing to a file is a  
xml/html cross cluster #@%$ of stuff. Here is some code:

if !params[:id].blank?  
@user = User.find\_by\_id(params[:id])

```
@xml = ::Builder::XmlMarkup.new
@unusedtickets = Unusedticket.find(:all, :conditions => ['user_id =

```

? and  
updated = true’, @user.id])  
end

@xml.DocumentElemnts{  
for unusedticket in @unusedtickets  
@xml.unusedtickets do  
@xml.account\_id(unusedticket.account\_id)  
@xml.locator(unusedticket.locator)  
@xml.ticketnumber(unusedticket.ticketnumber)  
@xml.traveler(unusedticket.traveler)  
@xml.issuedate(unusedticket.issuedate)  
end  
end  
}

headers[“Content-Type”] ||= ‘text/xml’  
headers[‘Cache-Control’] = ‘private’  
headers[“Content-Disposition”] ||= “attachment; filename=“test\_xml””  
render :text =\> @xml, :layout =\> nil

I really thought that if I said :layout =\> nil that would strip away all  
the html formatting, but apperantly not. Is there a way that I can write  
this information to a file and have it be strictly XML? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 5, 2009, 12:09am UTC](https://www.ruby-forum.com/t/output-xml-to-file/226046/2 "2009-08-05T00:09:49Z")

</div>

How about:

puts User.find\_by\_id(params[:id]).to\_xml

On Aug 4, 5:42 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
