# Store data in db from XML

**URL:** <https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352>\
**Category:** Deployment\
**Created:** [September 29, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352 "2009-09-29T13:00:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smit\_shah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@smit\_shah](https://www.ruby-forum.com/u/smit_shah)\
**Post date:** [September 29, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352/1 "2009-09-29T13:00:35Z")

</div>

Hi All…

I am trying to parsing data from XML. But I am not able to store it in  
database.  
Anyone have any idea about that???

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![smit\_shah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@smit\_shah](https://www.ruby-forum.com/u/smit_shah)\
**Post date:** [November 7, 2009, 7:09am UTC](https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352/2 "2009-11-07T07:09:08Z")

</div>

Smit S. wrote:

> Hi All…
> 
> I am trying to parsing data from XML. But I am not able to store it in  
> database.  
> Anyone have any idea about that???
> 
> Thanks in advance…

Hi smit,  
As you parse the xml data using feednormalizer gem. so you get  
it’s result in hash. now running loop for that hash, you are able to  
store xml data to your table. look below code, hope it’s solve your  
problem.

@rss = FeedNormalizer::FeedNormalizer.parse open(feed\_url)

if !@rss.entries.blank?  
for rss in @rss.entries  
@record = Model.new  
@record.url = rss.url  
Same way fill other attributes… in that table  
@record.save  
end  
end

Thanks,  
Priyanka P.

---

<div class="post-metadata">

**Author:** ![smit\_shah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@smit\_shah](https://www.ruby-forum.com/u/smit_shah)\
**Post date:** [March 4, 2010, 3:07am UTC](https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352/3 "2010-03-04T03:07:19Z")

</div>

you could also use rexml

[http://www.germane-software.com/software/rexml/docs/tutorial.html](http://www.germane-software.com/software/rexml/docs/tutorial.html)

---

<div class="post-metadata">

**Author:** ![smit\_shah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@smit\_shah](https://www.ruby-forum.com/u/smit_shah)\
**Post date:** [October 12, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/store-data-in-db-from-xml/176352/4 "2010-10-12T15:41:39Z")

</div>

rexml is a gem which can be used to parse xml into the DB dynamically.  
you have to first store the xml into an array and then use for loop and  
insert function to store in mysql.
