hema gonaboina
2008-Nov-28 07:09 UTC
how to convert the hash to xml - "Not all elements respond to to_xml"
Hi, I have a problem.. I am Working on Rails with Flex. I am getting a xml from the flex form.. I need to get the xml and has to insert the record The xml I am getting in the form as... <root> <insert> <number> 100 </number> <name> "xyz" </name> <address> <street> <street1> 12-32-122/34 </street1> <street2> 123 road </street2> </street> <city> unknown </city> <state> state </state> <country> In </country> <zip> 321456 </zip> </address> <job> Developer </job> . . </insert> <insert> <number> 101 </number> <name> "pqr" </name> <address> <street> <street1> 1-122/76 </street1> <street2> cross road </street2> </street> <city> city </city> <state> some state </state> <country> US </country> <zip> 321456 </zip> </address> <job> Developer </job> . . </insert> . . . </root> In these... each insert tag is a record which have to be entered into DB. But we are receiving the xml as HashWithIndifferentAccess params[:xml].class => HashWithIndifferentAccess We tried converting into hash h = (params[:xml]).Hash puts "#{h.to_xml}" it is showing the error as "Not all elements respond to to_xml" How to achieve the insertion are there any ways to get the xml... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-28 09:39 UTC
Re: how to convert the hash to xml - "Not all elements respond to to_xml"
On Nov 28, 7:09 am, "hema gonaboina" <hema.soli...@gmail.com> wrote:> Hi, > > I have a problem.. > I am Working on Rails with Flex. > I am getting a xml from the flex form.. I need to get the xml and > has to insert the record > The xml I am getting in the form as... > <root> > <insert> > <number> > 100 > </number> > <name> > "xyz" > </name> > <address> > <street> > > <street1> 12-32-122/34 </street1> > <street2> 123 road </street2> > </street> > <city> unknown </city> > <state> state </state> > <country> In </country> > <zip> 321456 </zip> > </address> > <job> > Developer > </job> > . > . > > </insert> > <insert> > <number> > 101 > </number> > <name> > "pqr" > </name> > <address> > <street> > > <street1> 1-122/76 </street1> > <street2> cross road </street2> > </street> > <city> city </city> > <state> some state </state> > <country> US </country> > <zip> 321456 </zip> > </address> > <job> > Developer > </job> > . > . > > </insert> > . > . > . > </root> > > In these... each insert tag is a record which have to be entered into > DB. > But we are receiving the xml as HashWithIndifferentAccess > params[:xml].class => HashWithIndifferentAccess >Rails parses the xml for you (into a hash). you can get the raw body of the request if you want (@request.body) Fred> We tried converting into hash > h = (params[:xml]).Hash > puts "#{h.to_xml}" > > it is showing the error as "Not all elements respond to to_xml" > > How to achieve the insertion are there any ways to get the xml...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---
Hema Gonaboina
2008-Nov-28 11:25 UTC
Re: how to convert the hash to xml - "Not all elements respond to to_xml"
Frederick Cheung wrote:> On Nov 28, 7:09�am, "hema gonaboina" <hema.soli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> � � � � � � � � � � � � � � � � 100 >> � � � � � � � � � � � � � � � � � <city> unknown </city> >> � � � � � � � � </insert> >> <street1> 1-122/76 </street1> >> � � � � � � � � � � � �. >> � But we are receiving the xml as HashWithIndifferentAccess >> � params[:xml].class => �HashWithIndifferentAccess >> > Rails parses the xml for you (into a hash). you can get the raw body > of the request if you want (@request.body) > > FredThank You Fred for your response But, I didn''t get you.. Can U explain me with example.. I need the xml only but i am receiving object of class HashWithIndifferentAccess.. so i am trying to convert into pure Hash and then to xml.. How to receive the value as xml ? If it works no need of conversion.. How to use the @request.body ? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-28 11:30 UTC
Re: how to convert the hash to xml - "Not all elements respond to to_xml"
On Nov 28, 11:25 am, Hema Gonaboina <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> But, I didn''t get you.. Can U explain me with example.. I need the xml > only but i am receiving object of class HashWithIndifferentAccess.. so i > am trying to convert into pure Hash and then to xml.. > How to receive the value as xml ? > If it works no need of conversion.. > How to use the @request.body ? > --Don''t know how else to explain it - request.body ( my mistake - the @ there is deprecated) is exactly the bytes that were sent to you. Trying to convert the hash back to xml seems completely circular (and HashWithIndifferentAccess is almost the same as Hash - the only difference is that you can use symbols or strings for the keys and they are considered identical) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hema Gonaboina
2008-Nov-28 11:33 UTC
Re: how to convert the hash to xml - "Not all elements respond to to_xml"
Hema Gonaboina wrote:> Frederick Cheung wrote: >> On Nov 28, 7:09�am, "hema gonaboina" <hema.soli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> � � � � � � � � � � � � � � � � 100 >>> � � � � � � � � � � � � � � � � � <city> unknown </city> >>> � � � � � � � � </insert> >>> <street1> 1-122/76 </street1> >>> � � � � � � � � � � � �. >>> � But we are receiving the xml as HashWithIndifferentAccess >>> � params[:xml].class => �HashWithIndifferentAccess >>> >> Rails parses the xml for you (into a hash). you can get the raw body >> of the request if you want (@request.body) >> >> Fred > > Thank You Fred for your response > > But, I didn''t get you.. Can U explain me with example.. I need the xml > only but i am receiving object of class HashWithIndifferentAccess.. so i > am trying to convert into pure Hash and then to xml.. > How to receive the value as xml ? > If it works no need of conversion.. > How to use the @request.body ?I worked on it.. and found that it is collecting as hashes with arrays in between in out case it is as {"root" => {"insert"=> [{"name"=>"xyz","address"=>[{"city"=>"city","state"=>"state"....}],"job"=>"developer",....},{"name"=>"pqr","address"=>[{},{}...],..}]}} That is it takes arrays between the hashes.. -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---