View Full Version : XML Parsing vs. DB Connection
kraftomatic
12-24-2003, 03:47 PM
Which uses less "resources" and loads faster?
My initial guess is a db takes longer. However, using a server side scripting language (ASP), along with an XSL and XML file, I'm not so sure ..
Happy Holidays and thanks.
Well, XML is simpler than most databases (what are you using, by the way? I'll guess MySQL for the duration of this). My general guideline is: 1 field needed: flatfile
1-4ish fields needed: XML file
>4 fields needed: DatabaseAnd yeah, xml is much faster, due to it's convenient syntax.
kraftomatic
12-24-2003, 04:17 PM
Well, it would normally be mySQL, but given my current host, it would be Access.
Even more of a reason to stick with XML ..
Thanks.
brothercake
12-29-2003, 01:02 AM
The advantage of a database over XML is that with a DB your script only has to search the index, not the whole database, whereas if you process XML you have to open the entire file, even if you use an XPointer.
For large data documents (100-150K+) you may begin to notice the difference in processing speed, but for less than that it's unlikely.
If you're looking for reasons to stick with XML, there are lots of others - ease of working with it, interoperability and easy transferance between systems, having a semantic structure for the stored data. These among others may outweigh the disadvantage of increased parsing time.
M@rco
12-30-2003, 07:01 PM
Since you're using ASP, you can use a free-threaded DOM object to virtually eliminate parsing overhead (i.e. it only happens once)...
At application start, load the XML into a free-threaded DOM and store it in an application variable. Use it in all your scripts, remembering to lock the variable before access and unlock it afterwards. Also make sure you save the XML file to disk whenever you modify it (depending on how frequently this is, you may want to implement a periodic saving mechanism instead).
;)
I've decided to revive this thread with a case study — my own CMS.
In my root folder, there is 'archives', within which there will be a folder for each year (04, 05 etc.). Within each early folder, there is a folder for each month. (01, 02, 03 etc.) Within each monthly folder, I have a file called data which stores all the posts from that month. At the moment it's a .xml file, but I'm thinking of changing it to a mySQL database. Here is what it contains.<blog month="02">
<post>
<title>Hello World</title>
<date>15th feb 04</date>
<uri>%uri-of-post%</uri>
<postbody>
<paragraph>Paragraph 1</paragraph>
<paragraph>Paragraph 2</paragraph>
...
</postbody>
</post>
...
</blog>I'm also thinking of adding in a description field as well. As you can see, this is starting to get very lengthy — I'm anticipating files of up to 30kb.
Should I change this to a mySQL database?
M@rco
02-15-2004, 08:04 PM
30KB is a very small amount of data, so that's not going to be a problem. If that's the sole reason that you think you should switch to MySQL then I suggest that it would be a complete waste of time.
You haven't said anything about how your script is actually using the XML, so there's absolutely nothing for me to go on.
Furthermore, re-reading this thread, I *completely* disagree with the statements you made in your original post - it appears to me to be very "stick a finger in the air and see which way the wind's blowing" kind of approach, and is NOT the way that such an issue should be approached! (Not sure how I completely missed it the first time around)
But that's just my opinion... ;)
Could you give an estimate on when filesizes become to great?
Time isn't really an issue. If I think I can get faster loading times with mySQL, I will switch.
When a user opens the page associated with a post, that page contains some PHP which sends a parameter to an XSLT file sitting in the archives/ directory, which is used to parse the data.xml file and root out a post with a title equal to the one sent.
M@rco
02-17-2004, 06:21 PM
Originally posted by me'
When a user opens the page associated with a post, that page contains some PHP which sends a parameter to an XSLT file sitting in the archives/ directory, which is used to parse the data.xml file and root out a post with a title equal to the one sent. Ah! You're using PHP! Then I can't help you. And besides, you still haven't given us much to go on.
Anyone? :confused:
Tails
02-25-2004, 10:50 PM
Okay I know nothing about databases, but I think they are overrated. With php, you can read and write files (up to 4 kb?) providing there are file permissions and stuff set for it. So what stops someone from using substrings and other features to read and write to an XML file instead of purchasing a database in their hosting plan? And 4 kb isn't really a limit if you can array your files according to sections, etc.
M@rco
02-26-2004, 12:15 AM
Originally posted by Tails
Okay I know nothing about databases, but I think they are overrated.>>completely speechless<<
:eek:
(What can you say to something like that?!! Answers on a postcard please...)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.