preface: its late and im tired, please keep this in mind when reading
XML is not meant to be a replacement of a database... it is meant to be a language-independant method of communication... a lot of people use xml becasue its cool to play with and not because its needed... databases have security.. xml are just flat files...
BAD XML Situation 1)
you have some data in the database... a product... you would like to display that product on a webpage... you ask MYSQL for the information, create an XML document representing that information, find the XSLT transformation for that docuemnt which will map it into html for you and apply it... this stupid please don't do this
XML Situation 1)
if you have data in your native database... and want to give it out to others that aren't using your database, and don't know your table structure, and your db specifics... you can give it to them as an xml document... and no matter what language they are using c, c++, Ruby, Python, Php, Java they will be able to translate the info into somthing usefull.. this is what RSS Feeds are all about they give you the raw info in a known format... you pretty it up and show it however you want... however even this situation has you keeping info in a RDBMS and only keeping a second represnetation of it in xml
XML Situation 2)
ok here is one instance where you might want to think about using xml instead of storing data in your database:
relations databases are designed to do certian things very well... join and query info... if you have a small amount of information that you do not need to join with anything else ever... you don't really need a relational database to hold it...
CONFIG FILES:
say you give each user on your site controll over what widgets appear on their page... a user specific config file.... you will only even need that info for one user... and one user only...
ok in a relational database you would need one Users table USERS and one USER_WIDGETS table...
that widgets table would need the ability to store per row all the info about one widget a user wanted... but each widget is different and may contain lists of data.... like say you have a bookmarks widget. In it are a list of bookmarks.... but each users bookmark widget can contain an arbitrary number of links... rows can't store arbitrary numbers of items, they are set. you need a table for storing arbitrary numbers.. so you drop an id in the widget table that points to some other table
ok you need three tables to hold this info...
USERS
-----
user1 ednark
...
USER_WIDGETS
------------
widget1 user1 bookmarkwidget
...
BOOKMARK_WIDGET_LINKS
---------------------
widget1 link1
widget1 link2
widget1 link3
widget1 link4
...
BOOKMARK_LINKS holds a many to one relationship with WIDGETS, and WIDGETS holds a many to one relationshtip to USERS
now to pull all the info about one user out of the database:
you can use three calls (heavy on your database for just such a simple relationship)
call 0) SELECT FROM USERS user = userid
call 1) SELECT FROM USER_WIDGETS WHERE user = userid_from_last_call
call 2) SELECT * FROM BOOKMARK_WIDGET_LINKS where bookmarkwidget = bookmarkwidget_id_form_last_call
you can also select it all in one call: joining all the tables.. but this would be a massive join as these tables hold a lot of rows and joining is row expensive...
now you havent even stored info about how to display it yet... how many widgets per row... what order in each row... what widgets in each row... now you need even more tables.....
Now, most likely, you will not want to ask your database:
give me all users whose 4th widget in the 2nd row is a bookmark widget which contains a link to phpbuilder.com
You will want to ask your database:
give me all the widgets this user has... and all the info for each widget... with no exceptions
its very expensive to ask your database the last thing, and easier to ask your databse the first thing...
So now comes XML. you could just make a file outside of your database and then just load that everytime the user wants to know what widgets are on his frontpage... this can even contain the relations of what widgets are in what order, and in what rows... all in one small pass...
xml doesn't care how many subtags of what type are inside it, but a databse table does care how many columns it has and what each value type is for that column... (however this can be forced in xml with dtds and schemas)... ...
hence why you need a seperate table for the many-to-one relationship of links to bookmarkwidgets into numerous tables....
the same info could be stored as XML in this way:
<userconfig id="ednark">
<widgets>
<row>
<widget type="bookmark" id="widget1">
<link>
<uri>[url]http://phpbuilder.com[/url]</uri>
<display>Click here to go to PhpBuilder.com</display>
</link>
</widget>
</row>
<row>
<widget type="bookmark" id="widget2">
<link>
<uri>[url]http://phpbuilder.com[/url]</uri>
<display>Click here to go to PhpBuilder.com</display>
</link>
<link>
<uri>[url]http://phpbuilder.com[/url]</uri>
<display>Click here to go to PhpBuilder.com</display>
</link>
</widget>
</row>
<widgets>
</userconfig>
each user could have their own file in a known location... every time you want to know what widget links they have... its one fileread and one parse away
now because all your data is in seperate files you can't ask you xml system this question very easily:
what links are the same between users 1, 2, 3, 4, and 5?
it would require 5 file reads 5 parses and a lot of php compares
You can ask xml easily to dump all the info at once from one user much faster that you can get from your database...
in a situation like this you might be better off using XML to store your data longterm...