# XML into database

**URL:** <https://discuss.rubyonrails.org/t/xml-into-database/46709>\
**Category:** rubyonrails-talk\
**Created:** [October 9, 2009, 9:35am UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709 "2009-10-09T09:35:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaap\_Haagmans](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jaap\_Haagmans](https://discuss.rubyonrails.org/u/Jaap_Haagmans)\
**Post date:** [October 9, 2009, 9:35am UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/1 "2009-10-09T09:35:39Z")

</div>

Hi,

I've already talked about this in another topic, but I've found another approach.

We have some complex definitions and structures in our database and I'd like to make it possible to simplify adding items to the application. I'd like to do that using XML. Using XML we'll define a few common item structures that can be used as a template for new items. But I don't want to actually store physical XML-files on the server, I want to store the XML in a database. Now my question is: how to do that? I know how to store it, but I don't know how to read it.

The sequence is quite simple. If a user wants to create a new item from a template, they select the appropriate template and the XML needs to be parsed so that the right values are copied into the right tables. Is this possible and how? The XML-parsers I know need to be fed from a file and I don't want to do that.

Thank you!

---

<div class="post-metadata">

**Author:** ![Walter\_McGinnis](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@Walter\_McGinnis](https://discuss.rubyonrails.org/u/Walter_McGinnis)\
**Post date:** [October 9, 2009, 10:15pm UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/2 "2009-10-09T22:15:45Z")

</div>

We do this in the Kete app ([http://github.com/kete/kete](http://github.com/kete/kete)). Look in lib/ extended\_fields.rb for example code.

In hindsight, I would probably have been better off to have done this  
with either marshalling or YAML rather than storing XML though.

Cheers, Walter

---

<div class="post-metadata">

**Author:** ![Jaap\_Haagmans](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jaap\_Haagmans](https://discuss.rubyonrails.org/u/Jaap_Haagmans)\
**Post date:** [October 10, 2009, 7:37pm UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/3 "2009-10-10T19:37:22Z")

</div>

Thanks for the tip!

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 10, 2009, 7:41pm UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/4 "2009-10-10T19:41:51Z")

</div>

jhaagmans wrote:

> Hi,
> 
> I've already talked about this in another topic, but I've found another approach.
> 
> We have some complex definitions and structures in our database and I'd like to make it possible to simplify adding items to the application. I'd like to do that using XML. Using XML we'll define a few common item structures that can be used as a template for new items. But I don't want to actually store physical XML-files on the server, I want to store the XML in a database. Now my question is: how to do that? I know how to store it, but I don't know how to read it.

[...]

I would suggest that XML or YAML in the DB is the wrong approach. I understand that you want flexibility without needing to change the schema, so why not consider a document database such as CouchDB? It sounds like this is really what you're looking for.

Best,

---

<div class="post-metadata">

**Author:** ![Jaap\_Haagmans](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jaap\_Haagmans](https://discuss.rubyonrails.org/u/Jaap_Haagmans)\
**Post date:** [October 11, 2009, 11:19am UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/5 "2009-10-11T11:19:06Z")

</div>

> I would suggest that XML or YAML in the DB is the wrong approach. I understand that you want flexibility without needing to change the schema, so why not consider a document database such as CouchDB? It sounds like this is really what you're looking for.

Nope, I'm really looking for XML in a MySQL db. I hoped there was something like REXML to read XML from a database, but I can't find it.

We can always consider putting physical XML files somewhere, but I'd prefer putting it in the db.

---

<div class="post-metadata">

**Author:** ![Jaap\_Haagmans](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jaap\_Haagmans](https://discuss.rubyonrails.org/u/Jaap_Haagmans)\
**Post date:** [October 12, 2009, 10:42am UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/6 "2009-10-12T10:42:07Z")

</div>

Because I have a client who already manually defines these items in XML for another application.

---

<div class="post-metadata">

**Author:** ![Matt\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Matt\_Jones](https://discuss.rubyonrails.org/u/Matt_Jones)\
**Post date:** [October 12, 2009, 2:44pm UTC](https://discuss.rubyonrails.org/t/xml-into-database/46709/7 "2009-10-12T14:44:16Z")

</div>

What part of REXML::Document.new(xml\_string\_from\_the\_db) doesn't work for you? 🙂

--Matt Jones
