Hi all, I am making application in Rails 3 in which I am parsing XML file and I want to store one of the XML tag in XML format into Mysql database. I have used ''TEXT'' as a datatype to store XML formatted data. I am getting the XML format Tag data but when I store it into database I am getting an error. Can any one please help me that how can I store XML data into database? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 November 2011 14:07, Preksha Patel <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all, > > I am making application in Rails 3 in which I am parsing XML file and I > want to store one of the XML tag in XML format into Mysql database. I > have used ''TEXT'' as a datatype to store XML formatted data. > > I am getting the XML format Tag data but when I store it into database I > am getting an error.Show us the full error and stack trace please. Also a few lines of code around the error. We are not telepathic, at least I am not. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, Now I am not getting an error but XML values are stored like ''--0 \n''. Code is: doc.xpath(''//item'').each do |tag| @req = Hash.new @req = tag.children[9] detail.create( :my_field => tag.children[9] ) end And in detail_model.rb class Detail < ActiveRecord::Base serialize :my_field end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 November 2011 14:47, Preksha Patel <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > Now I am not getting an error but XML values are stored like ''--0 \n''. > > Code is: > > doc.xpath(''//item'').each do |tag| > @req = Hash.new > @req = tag.children[9]Have you used ruby-debug to break into the code here and see what tag.children[9] looks like? Have a look at the Rails Guide on debugging to see how to do this. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Hi, Thanks for the reply.. When I puts tag.children[9] like this: doc.xpath(''//item'').each do |tag| puts tag.children[9] @req = Hash.new @req = tag.children[9] detail.create( :my_field => tag.children[9] ) end I am getting the whole XML Tag. But this tag is not saving into the database. It is saving like ''--0 \n''. Is there any problem with my model or Datatype into the database?? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 4, 5:33 am, Preksha Patel <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > Thanks for the reply.. When I puts tag.children[9] like this: > > doc.xpath(''//item'').each do |tag| > puts tag.children[9] > @req = Hash.new > @req = tag.children[9] > > detail.create( > :my_field => tag.children[9] > ) > end > > I am getting the whole XML Tag. But this tag is not saving into the > database. It is saving like ''--0 \n''. Is there any problem with my model > or Datatype into the database?? >I think you''ll find that tag.children[9] is just an object representing the node, which doesn''t have much meaning without the document it belongs to. You need to call something like to_s or to_xml on it to turn it back into a string Fred> Thanks > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.