# To\_xml and from\_xml round robin ... exists?

**URL:** <https://www.ruby-forum.com/t/to-xml-and-from-xml-round-robin-exists/129275>\
**Category:** Rails\
**Created:** [February 16, 2008, 1:49am UTC](https://www.ruby-forum.com/t/to-xml-and-from-xml-round-robin-exists/129275 "2008-02-16T01:49:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [February 16, 2008, 1:49am UTC](https://www.ruby-forum.com/t/to-xml-and-from-xml-round-robin-exists/129275/1 "2008-02-16T01:49:51Z")

</div>

Im creating an api for my website and Im trying to roll my own.  
I know I can use activeresource and some other packages, but really what  
I would like is to be able to send simple xml data back and forth.

Im sticking with AR controllers since I use the respond\_to block to  
output results in amf (via RubyAMF) and xml. So for the respond\_to xml  
code, I want to be able to do

{}.to\_xml and get something that can be translated back equivalently. on  
the other end.

Right now, if I want to get and array from xml, I have to send xml like:  
“1234” to get params[:ids]  
and if its only “1”, then params[:ids] is not an array.

I know Rails 2.0 is trying to make a better AR#to\_xml function, but that  
doesnt aim at my use case.

Also something like [{:foo =\> [“bar”,“bar”,“bar”]}].to\_xml will throw an  
error as well.

Somebody has had to have written a mirroring to\_xml / from\_xml function  
by this point.

Can anyone point me in the right direction?

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [February 18, 2008, 12:47pm UTC](https://www.ruby-forum.com/t/to-xml-and-from-xml-round-robin-exists/129275/2 "2008-02-18T12:47:03Z")

</div>

On 16 Feb 2008, at 00:49, Aryk G. wrote:

> {}.to\_xml and get something that can be translated back  
> doesnt aim at my use case.
> 
> Also something like [{:foo =\> [“bar”,“bar”,“bar”]}].to\_xml will  
> throw an  
> error as well.
> 
> Somebody has had to have written a mirroring to\_xml / from\_xml  
> function  
> by this point.

Hash.from\_xml ?

Fred
