# Advice: XML vs. mySQL

**URL:** <https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893>\
**Category:** Ruby\
**Created:** [April 7, 2009, 5:08am UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893 "2009-04-07T05:08:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [April 7, 2009, 5:08am UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893/1 "2009-04-07T05:08:07Z")

</div>

Hello,

I am new to Ruby and looking for some advice on how to best approach a  
problem.

I am writing a Facebook application that will rely heavily on the  
manipulation of strings. I want to set up a class, allow users to  
create objects based on the class, and write it to XML file or a  
database. Each entry will be indexed (integer) for lookup and  
identification purposes. When I need to load a specific object I will  
build it based on the XML data and the defined class.

1. Is it possible to define a class and then initialize objects based on  
information contained within an XML file?

Example:

```
class Car
  attr_accessor :model
  attr_accessor :cost
  attr_accessor :year
end

y = Car.new (XML file contains data for model, cost, and year)

```

1. I plan to create XML file names based on the index (id) of the  
object.

2. There will possibly be tens of thousands of objects (derived from my  
class) and each object will contain at least 15 variables  
(strings/integers) all written to XML file or mySQL DB. This can  
potentially be a large amount of data. Should I examine mySQL or stick  
with XML? I want to keep this as simple as possible unless resource  
management dictates I take the road less traveled. The speed at which  
the data is accessed is most important. I plan to load into memory the  
files that are currently in use by a user to speed up the process so  
this makes me think that XML would suffice. Hope this makes sense!

Any opinions are welcome.

Thanks.

Dave

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [April 7, 2009, 5:17am UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893/2 "2009-04-07T05:17:24Z")

</div>

On Apr 6, 2009, at 20:07, David Autry wrote:

> build it based on the XML data and the defined class.  
> If these are Ruby objects, why don’t you use Marshal?

> I want to keep this as simple as possible unless resource  
> management dictates I take the road less traveled. The speed at which  
> the data is accessed is most important. I plan to load into memory  
> the  
> files that are currently in use by a user to speed up the process so  
> this makes me think that XML would suffice. Hope this makes sense!

Marshal is likely going to be significantly faster than any XML  
serialization mechanism you write.

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [April 7, 2009, 5:45am UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893/3 "2009-04-07T05:45:29Z")

</div>

Isn’t there a drawback in terms of updating old data?

Thanks.

-Dave

Eric H. wrote:

> On Apr 6, 2009, at 20:07, David Autry wrote:
> 
> > build it based on the XML data and the defined class.  
> > If these are Ruby objects, why don’t you use Marshal?
> 
> > I want to keep this as simple as possible unless resource  
> > management dictates I take the road less traveled. The speed at which  
> > the data is accessed is most important. I plan to load into memory  
> > the  
> > files that are currently in use by a user to speed up the process so  
> > this makes me think that XML would suffice. Hope this makes sense!
> 
> Marshal is likely going to be significantly faster than any XML  
> serialization mechanism you write.

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [April 8, 2009, 12:17am UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893/4 "2009-04-08T00:17:17Z")

</div>

On Apr 6, 2009, at 20:44, David Autry wrote:

> > > files that are currently in use by a user to speed up the process so  
> > > this makes me think that XML would suffice. Hope this makes sense!
> > 
> > Marshal is likely going to be significantly faster than any XML  
> > serialization mechanism you write.
> 
> Isn’t there a drawback in terms of updating old data?

Marshal provides methods to help you handle this, if you need them.  
Most of the time you won’t so long as you code mildly defensively.  
When you do need them, use marshal\_dump/marshal\_load or \_dump/\_load.

PS: Don’t top-post, it’s confusing.

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [April 7, 2009, 3:20pm UTC](https://www.ruby-forum.com/t/advice-xml-vs-mysql/164893/5 "2009-04-07T15:20:30Z")

</div>

Use a database and use memcache. XML files don’t scale.
