I've been working on database-driven web applications for a few years now and recently took on a project involving a CMS that is XML-capable. This has led me to think about the usage of XML/XSLT in general and in what situations it would be more useful than the approach I've always used, which is storing all of my data in a (My)SQL database and then using PHP/Python/etc. to work with it on the web as needed.
There's obviously something I'm not "getting" here.. could anyone give me examples of applications where storing the data in XML files instead of in a database would be preferable?
SQL is good tabular data -- data that easily fits into rows & columns. XML is good for hierarchical data -- data which has several levels of different sizes.
SQL is good for storage & searching. XML is good for transmitting & formatting.
Use XML to create files that need to be sent to other applications. XML is more suited as data interchange format than as data storage format.
The following link is not bad to describe when using XML: Why should I use XML ?
To quote This Book (Effective XML: 50 Specific Ways to Improve Your XML):
I think this sums it up, if a little bluntly. XML is a data interchange format. One can have XML parsing libraries that can query a DOM with XPath expressions but that is not the same thing as a DBMS. You can build a DBMS with a DOM/XPath interface but to get ACID properties or scale to large data sets you need to implement a DBMS engine and a data format with indexes, logging and other artifacts of a DBMS - which (by definition) makes it something other than XML.
Things I use XML for:
There's not a whole lot of overlap between those use cases and the use cases for a database. Some, but not much.
Ironically, where I'm making my heaviest use of XML at the moment is in a desktop app that builds an in-memory ADO DataSet and uses the DataSet's WriteXml and ReadXml methods to persist and retrieve it. I'm using ADO because it's whole lot easier to dynamically build a data model defined by metainformation using ADO than it would be to implement my own object model for the task.
So here's a case that looks like I'm using XML as a database. But I'm really not. I'm using an object model that happens to implement a lot of database-like functionality, and I'm using XML as its persistence format.
Don't.
Try SELECT author FROM book
I would never use any kind of XML to store my data.
We use XSLT transformations as a data abstraction layer in our SOA app. All objects send each other data in XSLT, so there is only one language they need to understand. Except for the database connector, which needs to be able to transform the data into SQL, for sending it to the DB.
This way you don't have SQL string generation distributed over a zillion objects in your app. Makes maintenance much easier.