xml 빌더를 사용했습니다. 다음 코드 스 니펫은 까다로운 xml 빌드를 다룹니다. 당신이 컨트롤러에서
,
require 'builder'
def show_xml
@xml = get_xml_data
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @xml }
end
end
def get_xml_data
xml = Builder::XmlMarkup.new#(:target=>$stdout, :indent=>2)
xml.instruct! :xml, :version => "1.0", :encoding => "US-ASCII"
xml.declare! :DOCTYPE, :html, :PUBLIC, "-//W3C//DTD XHTML 1.0 Strict//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
favorites = {
'candy' => 'Neccos', 'novel' => 'Empire of the Sun', 'holiday' => 'Easter'
}
xml.favorites do
favorites.each do | name, choice |
xml.favorite(choice, :item => name)
end
end
end