Should I use XML or a database?
Hi all,
My plans were to use XML, but I am now reconsidering the decision. The data to be stored is users for a Chat server.
1. Concurrent access - With a database, there are locks and provisions for simultaneous access. With XML, I would have to syncronise my methods since my app is multi-threaded.
2. Data update - With a database, I can just insert a record. With XML, I need to rewrite the whole XML file with the new record added.
3. Data selection - The 'select' statement offers much more flexibility than the getElementById and getElementsByTagName methods.
With all this in mind, does it make more sense to stick to a database?
Or are there methods to get around these problems that I am not aware of?
Thanks,
Dewang
[790 byte] By [
dewangs] at [2007-9-26 2:17:57]

Hi Dewang!
Its hard to tell without knowing all circumstances, but from what you are saying, a database seems to be the better solution. Just because XML is new it does not need to be the best solution. If your data is regular, i.e. fits into a relational model, and does not need to be exchanged between different programs running on different platforms there's little that is in favour of xml. That are xml's strong points: platform independance and semi-formal data.
If you still want to use xml, some ideas about how to implement it. If you need regular queries and/or updates on the data, you're certainly better of parsing the xml once (on startup) into a DOM tree. Access is much faster and most implementations should allow modifications (although there are some limitations). If you consider your system as stable, there is no need writing the data back to an xml file unless you stop the program. But what system would be stable. So it's certainly a good idea to write the data back at some stage. This should give you some more performance. But be warned, DOM implementations don't need to be thread safe, and I think none is.
Hope that helps,
mneumi
Besides coding to xml is more difficult than coding to databases . So creating application with xml is going to take a lot more time
Well, I dont think coding is much of a problem. Infact, I had already started, and done some part of it in XML. But then I got to thinking, hmm.... mainly about the points that I have mentioned above.
I guess I should have thought about it earlier :) but I did not know too much about XML then.
Came across what I percieve to be shortcomings (atleast for my app) while coding. Maybe someone can prove me wrong and I can work around these problems. If not, I think I'm going with a DB.
How would you call XML using JDBC?
huh? Did I say I was going to do that?
Is this in response to this post or are you asking a question of your own?
If you are asking a question - To the best of my knowledge (which is not extensive :) ) you can not. You have to use an api (such as JAXP) that allows you to parse an XML doc and retrieve the contents.
I think XML is more useful if you want to do data exchanging.
But in your case, I think store data in database is more convenient for search, update, delete, and insert new item.
And also, according to my experience, using database would get better performance.
So, IMHO, in this case, database is better.
You are making an assumption that commercial database
servers do not support XML. Not true any more. For
example check out Oracle databse's capability to store
XML and allow query on stored XML.
Rest assured that you will see more and more database
servers and application servers getting XML enabled in
this and next year.
Regards,
Soumen Sarkar
Atoga Systems Inc. (http://www.atoga.com)
And how about creating a database with one memo field, which strores a XML document. In case your database doesn't specifically support XML.
Where do I find this JAXP?
You can download JAXP from http://java.sun.com/xml/xml_jaxp.htmlClick on the link that says 'Products & APIs' for all the products.
This is an interesting concept and i'm sure this will come with time. Ideally, someone would have to implement an XML database server that manages the documents in a multi-threaded environment, like this guy is doing with his app. Then they would have to write JDBC driver to implement their servers communication protocol.
Not trivial to do, but i'm sure there are xml databases available that may allow you to interface via JDBC.
In reply to the original question, I would use a database, all the issues that have been outlined have been solved and implemented along time ago. Why re-invent the wheel, let someone else do it for you.
Well, thanks all.I have decided to go use JDBC atleast for now. Maybe, at a later date, as XML progresses, I might convert the app to use XML. But as of now, JDBC seems to be the way to go.Thanks again,Dewang
You could know more than I do about XML, but there are database servers called "native XML database" servers that store XML in its original form and allow you to interact with it using XQL.
This may not pertain to your project, but you can also use a relational database and map the tables to XML documents using XML API's.
porcaree