Help needed in xml feed

hello gentlemen

if i use the below code in model( I want this code to be in model only
not in views)

xml = Builder::XmlMarkup.new( :target => $stdout, :indent => 2 )
xml.instruct! :xml, :version => “1.1”, :encoding => “UTF-8”
xml.avails {
xml.dump(“hai”)
xml.dump1(“hello”)
}

how can i retrieve this code & feed this code into xml file (say
“demo.xml”)

plz explain with example

advance thx
Have a pleasant day

narayana