I recently had occasion to consider whether to use XML files or a traditional database when constructing a Web-based application at work. It took a lot of careful consideration and research to decide which way I was going to go.
In the end, I chose to use XML files, and I will explain why.
I am currently developing Web sites on two separate servers. One site, our main site, is live right now. It is hosted on our local server, which runs Microsoft IIS and uses the default installation of VBScript and MS Access 2003. The other site, a smaller offshoot of our Web site, will most likely go live within the next week or two. It is hosted on our new remote server, which is running on RedHat, with basically all of the bells and whistles (PHP 5, MySQL 5, Perl, Python, PostGreSQL, etc.).
The application I’m developing needs to be hosted on our main Web server. However, the output of the application will need to be available to the sites on both servers. I basically had three choices. The first option was to use MS Access. However, using Access would mean that I would need to work with our IT team to make sure that the Access database was freely available to our other server, and I would need to use the Access database connection scheme through PHP (which doesn’t really appeal to me). The second option was to use our remote MySQL database to host the information. However, again, that would mean that I’d need to work on making sure that the database was freely available to our other server (this time, it would need to be writable by our Windows server), and I would need to do a lot of studying to figure out how to interact with a remote MySQL server using nothing but VBScript (not .NET). That really did not appeal to me.
My final option was to use XML files. With XML files, I would simply need to make sure that they were readable by our remote server. That was easy enough.
So, I built the application using VBScript and XML files, rather than trying to connect to a database. Then, I wrote a very simple PHP script on the remote server that simply opens the XML file and reads it out into a variable. From there, I could pretty much do whatever I want with it.
What I finally ended up doing was building a VBScript class and a PHP class (one on each server, obviously) that reflects the structure of my XML. Then, when I read the XML file, I simply instantiate a new object for each element inside the file. That allows me to manipulate the information pretty much any way I want to within my scripts.
Have you ever had to choose between XML and a database? If so, what was the application you were working on, and what did you end up choosing?
EDIT – I thought I should also note that, for the purposes of my application, I did not need any relational information. Obviously, if I had had the need to refer to various pieces of information that related to one another (for instance, if I was building an application to store customer invoices, and I needed to be able to relate customer ID numbers with customer contact information with individual invoices, etc., I would not have chosen to use XML over a database). However, in this case, each collection of information was independent of the others, and did not require any relationships.
For those curious, I am building an application that allows our public relations professionals to post news releases. Therefore, the only information I really needed to store was the headline, the post date, the body text, an ID (so I have a unique way to differentiate between the various stories), and, in this case, a switch to determine which of our two organizations the news release relates to.