Advice: XML vs. mySQL

D

David Autry

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)

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

Example: IDs 1000 - 1099 would be in a file named 1000.xml
IDs 1100 - 1199 would be in a file named 1100.xml

3) 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
 
E

Eric Hodel

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.

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.
 
E

Eric Hodel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top