Where are the differences using XML and MySQL database? Which should I use? Where are the differences using XML and MySQL database? Which should I use? xml xml

Where are the differences using XML and MySQL database? Which should I use?


MySQL (or SQL Server, Oracle, DB2, etc.) are database engines: they're specific applications that were built for data storage and processing, and are very good at doing that; they also can run on a different server than the one where your main program is, allowing for load sharing.

XML files are just text files stored on your machine or another one; they need to be read, parsed and written to, and only your program can do that. They'are also really, really inefficient, because of their text nature: reading and parsing a text file is very slow, and modifying it is even worse.

XML files are good for storing configuration settings and passing data between different systems, but data storage and processing should definitely live in a proper DBMS.

Also, obligatory Joel Spolsky reference.


Consider if you have an XML document with a nested person element that contains information on each of your users, and you have 3000 users. If you want to pull the information for a single person, you're going to have quite the task of parsing through that huge file to find that person's information. You might could use some clever seeking to jump around the file, but ultimately there is going to be alot of sequential access.

With a database you will normally have indexes, which would allow you to very quickly perform searching tasks like the above. In the above scenario, finding an individual in an indexed table will probably be on the order of 100 times faster.


It depends a lot on what kind of data you want to store. If you are storing mostly document oriented stuff, XML can be a good choice. If you are storing lots of small hierarchies, XML is probably better than SQL. The time to read and parse an XML file is definitely more that the time needed to get a simple query out of a database. But if you have data that do not fit naturally in a database, the cost of query could go up dramatically and actually become more than just using XML files.

One other option you could try is using an XML database, for example Xindice (http://xml.apache.org/xindice/). XML databases are not that much used at the moment, mostly because we dont have good mathematical theories about hierachic databases. But they can be really usefull if you have the right problem ...