I noticed some sections in the "Agile Web Developement with Rails"
book:
"
Autogenerating the XML
In the previous examples, we generated the XML responses by hand, using
the
builder template. That gives us control over the order of the elements
returned.
But if that order isn’t important, we can let Rails generate the XML for
a model
object for us by calling the model’s to_xml method.
...
Note that by default to_xml dumps everything out. You can tell it to
exclude
certain attributes, but that can quickly get messy. If you have to
generate XML
that meets a particular schema or DTD, you’re probably better off
sticking with
builder templates.
"
So that confirms what I''m finding, that to_xml isn''t too great
for tight
control of your output. Builder is better. But does anyone know of a
best-of-both-worlds approach? I want JSON as an alternate output, so it
seems to make sense to create a hash structure mirroring the desired
output structure, but then for the XML I''d need to unpack and re-pack
the same structure within my builder definition.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.