Say I want to output XML like this:

<myXML>
  <id>123</id>
  <fruit>apple</fruit>
  <fruit>banana</fruit>
  <fruit>pear</fruit>
  <fruit>lemon</fruit>
</myXML>

Is there a way of doing that with to_xml?

It seems like there's two problems: to_xml always creates a wrapping
element <fruits> when it encounters an array, and...

You can put plain strings into hash values and it works, but plain
strings in arrays doesn't work. That's this guy's problem again
http://www.ruby-forum.com/topic/167577 .

Maybe I should look at using Builder instead. Seems it gives me power
over the XML output, but my code builds up a nested hash/array
structure. Dont I end up embedding knowledge of that structure in two
different places. Also from my hash I wanted to generate JSON too. Is
there an approach converting from an XML doc object to JSON? or some
other way I should be thinking about this?
-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to