Store data in db from XML

Hi All…

I am trying to parsing data from XML. But, I am not able to store it in
database.
So, any one can help me out???

Thanks in advance…

2009/9/29 Smit S. [email protected]:

Hi All…

I am trying to parsing data from XML. But, I am not able to store it in
database.
So, any one can help me out???

What is the problem that is preventing you from storing it in the db?

Colin

Colin L. wrote:

2009/9/29 Smit S. [email protected]:

Hi All…

I am trying to parsing data from XML. But, I am not able to store it in
database.
So, any one can help me out???

What is the problem that is preventing you from storing it in the db?

Colin

Hi Colin

I am using feednormalizer gem. I have written code like

@rss = FeedNormalizer::FeedNormalizer.parse open(feed_url)

I am accessing the values like “@rss.entries”.
I have a model named as Data in which I am storing that data.

@data = Data.new
@data.title = @rss.entries.title

But when I try to store in db it shows me like " allocator undefined for
Data".
Any idea???

2009/9/30 Smit S. [email protected]:

What is the problem that is preventing you from storing it in the db?
I have a model named as Data in which I am storing that data.

@data = Data.new
@data.title = @rss.entries.title

But when I try to store in db it shows me like " allocator undefined for
Data".
Any idea???

Data is a reserved word in rails (see
http://wiki.rubyonrails.org/rails/pages/ReservedWords). I suggest
using a different name for the model.

Colin

Colin L. wrote:

2009/9/30 Smit S. [email protected]:

What is the problem that is preventing you from storing it in the db?
I have a model named as Data in which I am storing that data.

@data = Data.new
@data.title = @rss.entries.title

But when I try to store in db it shows me like " allocator undefined for
Data".
Any idea???

Data is a reserved word in rails (see
http://wiki.rubyonrails.org/rails/pages/ReservedWords). I suggest
using a different name for the model.

Colin

Hey thanks dude… Its work
But now I am suffering from another problem. It stores in db but only
the first entry of XML file. I have written that code in for loop. My
code is as follow:

@rss = FeedNormalizer::FeedNormalizer.parse open(feed_url)
@rss = @rss.entries.paginate :page => params[:page], :per_page => 5 if
!@rss.blank?
@abc = Abc.new
for rss in @rss.entries
if !@rss.entries.blank?
@abc.title = rss.title
@abc.url = rss.url
end
end
@abc.save if !@rss.blank?

2009/9/30 Preksha P. [email protected]:

  @abc.title = rss.title
  @abc.url = rss.url
 end
end
@abc.save if !@rss.blank?

Would it be better to have the new and the save inside the loop so
that you make a new one and save it for each item? At the moment you
make a new object, loop round rewriting the values in @abc each time,
then save it once.

I presume you realise that the paginate call mean that will only get 5
at a time?

Also it might be worthwhile studying the rails guide on Debugging Rails
Apps at
http://guides.rubyonrails.org/ The techniques there may help you to
identify this sort of problem yourself.

Colin