Stupid Human Tricks with Ruby on Rails’ RXML, aka XML Builder
Tuesday, December 5th, 2006Man, I miss the old “Late Night with David Letterman” of the 80’s sometimes…
Alright, to the point. Ruby on Rails makes it extremely easy to generate nicely formed XML from your application, especially if you are simple doing something like the following:
def show
@topic = Topic.find(params[:id])
respond_to do |format|
format.html
format.xml { render
ml => @topic.to_xml }
end
end
If the request is for XML version of the topic, this will take all the attributes of a topic and make them into well formed XML. Nifty, but this doesn’t provide fine-grained control of the XML output which is what I need. RXML templates to the rescue:

