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?
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.
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 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
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.