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@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.

Search Discussions

  • Colin Law at Nov 3, 2011 at 2:17 pm

    On 3 November 2011 14:07, Preksha Patel 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@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.
  • Preksha Patel at Nov 3, 2011 at 2:47 pm
    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@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.
  • Clanlaw at Nov 3, 2011 at 3:30 pm

    On 3 November 2011 14:47, Preksha Patel 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@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.
  • Preksha Patel at Nov 4, 2011 at 5:33 am
    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@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.
  • Frederick Cheung at Nov 4, 2011 at 10:39 am

    On Nov 4, 5:33 am, Preksha Patel 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@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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 3, '11 at 2:07p
activeNov 4, '11 at 10:39a
posts6
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase