Database vs. XML
I can't realy get to understand how could XML be useful to store data for a database-driven web site. Isn't data already described when properly put in the database. I read about how to use XML to store content, and than use XSLT to create XHTML (layout), and use CSS to apply design to XHTML layout. But what I didn't get is when I read "...and you store your XML data into a database". What is the purpose of storing XML marked content into a database?
And when I think about dinamyc data driven web site, it seems illogical to use XML at all. If I want to do queries on my data it is best (I think) for the data to be in a database. For example: If I wanted to count how many articles were published on my site. This seems harder (and slower) to do without a database. It seems logical to use XML for exchanging data between different systems. But how could this benefit me at bulding non-static sites?
Well this are some of my thoughts. Please make some comments and enlighten me. How shoud I use these techologies?
My sentiments exactly. I also fail to understand the reasons behind it. I can see benefits of XML in the sense that you have an architectural, platform and database engine free means of describing your data. So in terms of portability it's excellent.
However, when trying to understand it's benefit over a database on sites that don't need to share information is harder to understand.
Well, the purpose of xml is to add structure to documents. If you have a database to populate an xml page, it will allow the user to interact with the xml dom, thus allowing the queryed arguments for sorting the page without reloading the page and pulling the content from mySQL, therefore saving resources as well.
can you provide an example or a link to an example that does that you just said?
I'm still trying to 'understand' xml and an example of what you said would be perfect.
I know nothing
June 10th, 2002, 09:22 AM
An example could be this:
We have a program that uses a folder tree. The tree itself is organised within a database, the underlying filesystem is flat. So 'here>there>everywhere>file.jpg' exists at 'files>file.jpg' and not where it would appear to be. A PHP script queries the database to create an XML file representation of this folder tree. This XML file is easily parsed into a physical representation of a collapsing/expanding folder tree, that maintains the illusion. Because an XML file is being created it means that the file can be used by more than one application, which it is, without more database connections being made. It also means that a state can be saved so that when the page is reloaded the folder tree remains in the expanded state that it was left in. If a file/folder is added then the XML file is recreated, otherwise it is the same file that is used for subsequent uses.
Another use for XML database interaction is to have two dimensions within a table. If some data is going to be static, instead of having a lookup table you can simply insert the data as a blob of XML that can parsed on retrieval, it may go against the RDB and data integrety concept but it makes things quicker and simpler, which is sometimes needed. For example, you could 'roll up' all the news from today into a single XML file and put in a database table with fields NEWS_DATE and NEWS_TEXT, then you would have a simple store but retain a degree of formatting possibility by inserting all the news as one blob of XML. It's tidier than having a massive number of entries for one day.
June 10th, 2002, 09:33 AM
You can also use XML files in a way similar to what binky mentioned for a cheapo "version control" system in a CMS.
When a document is edited, you create an XML version that represents the document at it's current state. You then store this XML version, along with an ID and a datetime string in a table. You can now list different versions of document over time and restore them if needed. Works pretty slick. If you're a perl person, check out XML::Simple and/or Data::Dumper to make this easy as pie.
June 14th, 2002, 02:36 AM
So let me see if I've got the idea:
1) I want to retrieve a list of titles of books.
a. SELECT title, date FROM books;
b. Then I use PHP to pull the data from my database and paste it to the client browser.
2) But the user wants to also be able to sort this data by the date:
a. SELECT title, date FROM books ORDER BY date;
b. Then paste the data again using PHP
If I were to use XML, I could transfer the duty of ordering the data completely to the client browser, thus bypassing the two steps in #2 above, completley? I would just use the data already retrieved in #1, and have XML tell the browser to do the sorting? If so, now that sounds like a good deal indeed.
That would essentially cut the resource load on the server in half.
June 14th, 2002, 02:58 AM
That's a neat idea. Thanks.