# Powerfull XML Deserialization of ActiveRecord object

**URL:** <https://www.ruby-forum.com/t/powerfull-xml-deserialization-of-activerecord-object/138762>\
**Category:** Rails\
**Created:** [May 27, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/powerfull-xml-deserialization-of-activerecord-object/138762 "2008-05-27T15:14:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [May 27, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/powerfull-xml-deserialization-of-activerecord-object/138762/1 "2008-05-27T15:14:37Z")

</div>

Hi,

i m trying to deserialize XML that came from a model class.  
To serialize i use “to\_xml” method like :

Foo.find(:all).to\_xml(:include=\>[:foo2])

Now i m trying to deserialize it.  
I tried to use “Hash.from\_xml” but it doesn’t take care of the  
associations.

I found someone who wrote his own “from\_xml” method that take care of  
associations.  
here is the code : [http://riftor.g615.co.uk/index.php?action=view&id=20](http://riftor.g615.co.uk/index.php?action=view&id=20)

The problem occur with this piece of code :

root.elements.inject([]) do |instances, element|  
instances.push(self.from\_xml(element))  
end

Here is the error :

NoMethodError: private method `gsub!' called for []:Array from /Applications/Locomotive2/Bundles/ rmagickRailsMar2007_i386.locobundle/framework/lib/ruby/1.8/rexml/ parsers/xpathparser.rb:20:in `parse’  
from /Applications/Locomotive2/Bundles/  
rmagickRailsMar2007\_i386.locobundle/framework/lib/ruby/1.8/rexml/  
xpath\_parser.rb:57:in `parse' from /Applications/Locomotive2/Bundles/ rmagickRailsMar2007_i386.locobundle/framework/lib/ruby/1.8/rexml/ xpath.rb:53:in `each’  
from /Applications/Locomotive2/Bundles/  
rmagickRailsMar2007\_i386.locobundle/framework/lib/ruby/1.8/rexml/  
element.rb:947:in `inject' from ./script/../config/../config/environment.rb:152:in `from\_xml’  
from (irb):3

To try to use it put his code at the bottom of environment.rb

If any one could help me,  
and help others after me with this kind of needs…

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [May 27, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/powerfull-xml-deserialization-of-activerecord-object/138762/2 "2008-05-27T18:28:45Z")

</div>

Am i the only one who want to deserialize xml 🙂 ??

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [May 28, 2008, 12:17am UTC](https://www.ruby-forum.com/t/powerfull-xml-deserialization-of-activerecord-object/138762/3 "2008-05-28T00:17:11Z")

</div>

really, no one ?

goch…
