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 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 :) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Differenthink
2008-May-27 16:27 UTC
Re: Powerfull XML Deserialization of ActiveRecord object
Am i the only one who want to deserialize xml :) ?? On 27 mai, 15:14, Differenthink <guillaume.mont...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > 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 :)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Differenthink
2008-May-27 22:16 UTC
Re: Powerfull XML Deserialization of ActiveRecord object
really, no one ? goch... On 27 mai, 18:27, Differenthink <guillaume.mont...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Am i the only one who want to deserialize xml :) ?? > > On 27 mai, 15:14, Differenthink <guillaume.mont...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > > 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 :)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---