Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using xml?

Status
Not open for further replies.

jonniejoejonson

Programmer
Nov 6, 2006
3
0
0
GB
I am trying to work out when or why I would use xml over a database. I have finally thought of a scenario. I want users to leave other users comments. Therefore instead of storing this in a database as this database would become to big as it would contain all comments for all users, it would be easier to store each users coments to their own xml.

However with a database I can limit the amount of info I get out of

How does one simply write and manipulate an xml file?.
I assume you could use php?
Hoever I can't seem to find a simple way of adding to an xml file without having to open and save the whole file each time. Or simply reading parts of teh xml, not the whole file.

If anyone can tell me if that all this possible, and could recommend any good tutorials that would be much appreciated. Jonnie.
 
I think you have your scenario exactly backwards: the more data you have to deal with, the better off you'd be with a database. Remember, you're going to have to choose between SAX/DOM parsers, and DOM requires memory for the entire XML file, real or swapped.
I can't seem to find a simple way of adding to an xml file without having to open and save the whole file each time. Or simply reading parts of teh xml, not the whole file.
Bingo!

Ever use iTunes for an iPod? Slooooow start-up, no? Guess why: although it uses an internal database, it keeps a copy of your music collection data in an enormous (OK, it's directly proportional to the size of your collection) XML file.

Moral: Use a database for database applications.
 
I'm with harebrain.

A google search on xml vs database could help you to get a clearer idea.

Cheers,
Dian
 
Also look into one-to-many relationships in a relational database.

Instead of having a field in each record for every other user to record a comment, try this:

1) Assign a number to each user. This number gets stored with the rest of the user's information.
2) Create a second table within the database to store comments. Each record in this table is of the form:
UserID -- the ID of the user being commented on
CommentUserID -- the ID of the user writing the comment
Comment -- the text of the user's comment
UserID and CommentUserID together form the key.

This is fine if each user can only make one comment about each of the other users. If users may make multiple comments, you'll also need a CommentNumber field which is filled in sequentially for each UserID/CommentUserID pair, and is included in the key for the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top