Im trying to create an xmlrpc service. Rails by default uses xml_simple to parse incoming raw xml data into a hash. The problem is, that if I start out with a hash like this: hash = {:books => [{:id=>4,:key=>3}, {:id=>644, :key=>54}]} and convert it to xml via to_xml, when I read it back in, it ends up doing something like: result_hash = {:books => {"book" => [{...},{...}}]} so I end up accessing the books array with hash["books"]["book"] Has anyone experienced this before? -- 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 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 -~----------~----~----~----~------~----~------~--~---
Josh Susser
2007-Nov-15 04:26 UTC
Re: xml to hash/array and back to xml again with xml-simple?
Aryk Grosz wrote:> Im trying to create an xmlrpc service. Rails by default uses xml_simple > to parse incoming raw xml data into a hash. > > The problem is, that if I start out with a hash like this: > > hash = {:books => [{:id=>4,:key=>3}, {:id=>644, :key=>54}]} and convert > it to xml via to_xml, when I read it back in, it ends up doing something > like: > > > result_hash = {:books => {"book" => [{...},{...}}]} > > so I end up accessing the books array with hash["books"]["book"] > > Has anyone experienced this before?Yes. Rails does some extra post-processing on the xml-simple results to get something that works. What version of Rails are you using? Some of that behavior changed a few months ago. I like the description of xml-simple as neither xml nor simple. It seems to work ok for REST and ARes though. But if you''re doing xmlrpc you should be using a real xmlrpc package. -- Josh Susser http://blog.hasmanythrough.com -- 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 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 -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2007-Nov-15 05:45 UTC
Re: xml to hash/array and back to xml again with xml-simple?
Im using rails 1.2.5, is there more improvements on that? Also, which package do you recommend. The thing is, is that many of these api/service methods have a respond_to block which implements other mime-types. Now I can do format.xml{render :xml => "<xml>"}, but im not sure if i can do that if i use a package, can I? Josh Susser wrote:> Aryk Grosz wrote: >> Im trying to create an xmlrpc service. Rails by default uses xml_simple >> to parse incoming raw xml data into a hash. >> >> The problem is, that if I start out with a hash like this: >> >> hash = {:books => [{:id=>4,:key=>3}, {:id=>644, :key=>54}]} and convert >> it to xml via to_xml, when I read it back in, it ends up doing something >> like: >> >> >> result_hash = {:books => {"book" => [{...},{...}}]} >> >> so I end up accessing the books array with hash["books"]["book"] >> >> Has anyone experienced this before? > > Yes. Rails does some extra post-processing on the xml-simple results to > get something that works. What version of Rails are you using? Some of > that behavior changed a few months ago. > > I like the description of xml-simple as neither xml nor simple. It seems > to work ok for REST and ARes though. But if you''re doing xmlrpc you > should be using a real xmlrpc package. > > -- > Josh Susser > http://blog.hasmanythrough.com-- 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 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 -~----------~----~----~----~------~----~------~--~---