# Howto rebuild a object from a received xml hash structure?

**URL:** <https://www.ruby-forum.com/t/howto-rebuild-a-object-from-a-received-xml-hash-structure/125382>\
**Category:** Rails\
**Created:** [January 8, 2008, 6:41pm UTC](https://www.ruby-forum.com/t/howto-rebuild-a-object-from-a-received-xml-hash-structure/125382 "2008-01-08T18:41:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [January 8, 2008, 6:41pm UTC](https://www.ruby-forum.com/t/howto-rebuild-a-object-from-a-received-xml-hash-structure/125382/1 "2008-01-08T18:41:58Z")

</div>

im my web server app , i have an action to be used as a REST web  
service

# GET /user/membership.xml?email=emailaddress

def membership  
@user = User.find\_by\_email(params[:email])  
respond\_to do |format|  
format.xml { render :xml =\> @user.to\_xml( :only =\>  
[ :first\_name, :last\_name, :display\_name, :membership\_type,  
:membership\_at], :skip\_types  
=\> true)}  
end  
end

my client web app get it :

```
@referee = Referee.new(params[:referee])
url = "http://#{WWW_HOST}/user/membership.xml?

```

email=#{params[:referee][:email]}"  
result = Net::HTTP.get(URI(url))  
data = XmlSimple.xml\_in(result)

------------ GOT IT BACK  
data  
=\> {“last-name”=\>[{“nil”=\>“true”}], “display-name”=\>[“chane850”],  
“first-name”=\>[{“nil”=\>“true”}], “membership-  
at”=\>[“2007-03-28T21:25:31Z”]}

how can I rebuild a membership object (not active record) from it, to  
reuse it late  
@membership = Membership.new  
@membership.last\_name = data ??? that’s the question !!!  
…

thanks for your lights

Erwin

---

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [January 9, 2008, 2:36am UTC](https://www.ruby-forum.com/t/howto-rebuild-a-object-from-a-received-xml-hash-structure/125382/2 "2008-01-09T02:36:09Z")

</div>

have you tried using the magic of activeresource (the web services bit  
not just the nice routes and helpers)

try this link for starters. It’s a little out of date, but  
activeresource has just got a whole lot better  
[http://ryandaigle.com/articles/2007/3/14/rest-activeresource](http://ryandaigle.com/articles/2007/3/14/rest-activeresource)

You should be able to just make a class that inherits from  
ActiveResource::Base and it will interface nicely with your web server  
app.

Joe
