LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2005, 08:52 PM   #1
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Rep: Reputation: 32
Storage: XML vs plain text?


What do you think is better for data storage, XML or a plain text file delimited by spaces or some other character? I am writing a small program (basically an address book), and I am wondering what to use for a file format. Any opinions would be appreciated (either for an address book or just in general).
 
Old 12-13-2005, 10:59 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If it really is a small personal proj, I'd be inclined to go with a basic flat file, using a delimiter eg comma or maybe tilde (~) as field separator.
Depends what you are trying to do/learn.
XML is prob overkill, unless you want to learn it.
The lang you are using also has an effect on your options eg in Perl look at using a tied hash.
What sort of access / searching will you be doing?
If it's going to be a bigger proj, look into MySQL for example...
 
Old 12-14-2005, 03:34 AM   #3
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
Many languages these days have an XML API that allows you to store your data in object tree, and when you want to save it, you just call a single save method. It's very easy... doesn't actually teach you much about XML, but easy to use.
I wouldn't worry about trying to write XML without an API, though -- if you're writing the file directly, I'd stick with plain text; manually generating XML is far too much like hard work.

The main advantage of XML is that it makes your data much easier to use outside of your program. XML is [relatively] easy to transform from one type to another. Or you could work the other way too, and consider using an existing XML format; there may be a standard you can use that will mean you can share data with other apps.
 
Old 12-14-2005, 03:19 PM   #4
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Original Poster
Rep: Reputation: 32
Basically I am only reading the file in the program to search names and such; entries would be added by manually editing the file.

Do people think XML is a good storage format in general? I'm interested to hear opinions.
 
Old 12-14-2005, 10:59 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you have a lot of data, it's hard on the eyes, so use an API. It can be useful if you want to share data among commercial programs, as thet may have an XML load/unload interface.
 
Old 12-15-2005, 01:47 AM   #6
ppanyam
Member
 
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
XML vs Flat File

Having your data in XML means that your DATA is already stored as Objects. Your data is already validated and tested.

Also same XML data can be shared by programs which are probably written in different languages. For example, if your address book becomes a hit and if you need to share the data with your friend, who wishes to put it on intranet, it will be easy for him to access it through API of his choice.

If the entries are going to be 15 or 20, dont bother with XML. Use CSV instead. If the entries are in thousands, use a database. For others you may use XML. Ofcourse you can use XML in the other two scenarios above, but it may not be ideally suited.
 
Old 12-15-2005, 08:27 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
XML phew

I've got loads of XML data.
(it's the new thing, we gotta have it. why's that then? it's the new thing. right)

I'm working on a data set of 1600 XML documents.
About 1G of data. Not massive but fairly big.

It sucks big time.

We got an XML database.
ditto.

It's expensive, comlicated and slow. (like M$: Why store data in one byte when you can use 10k?)
I gave up on the XML database as it would break If i sneezed in the same building as the server
or someone opended a calculator on the machine.

You try and Xquery the data and each process needs six hundred squiddly megas of RAM
just to start. I had to fudge my Xqueries into multiple calls via shell scripts; where
if i tried multiple documents it asked for 300 mega tera giggle dyna-bytes more RAM.
Also it takes all bloody day to do something complicated.
It's like using bloody windows.

Xquery is very nice in principle, but when I'm asked to grab some data they get upset
when I tell them to ring back when Buddha has his next visit.

I've ended up using, perl, sort, uniq, C, ksh etc. to get a decent performance.

Phew, sorry about the rant


I can't see any advantages as a storage medium. Maybe for transferring data.
But still it's *just* a markup language.
 
Old 12-15-2005, 06:03 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I tend to agree with billy. I was trying to be neutral in my prev responses, but personally, I either user something simple eg CSV, or a custom format or a DB.
XML just seems like overkill/bloated most of the time. I guess it should gzip reasonably efficiently...?
As I said passing data to commercial progs may entail XML as it's the trendy i/f std atm, but many will aslo have CSV or DB drivers...
Data formats are definitely a "use the right tool for each job" deal.
 
Old 12-15-2005, 11:33 PM   #9
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Original Poster
Rep: Reputation: 32
Ok, thanks. In my (relatively short) experience, it seems that while XML-formatted data is easier to read, write, and make sense of in a text editor, the APIs for reading and writing XML in a C(++) program are hugely complicated - for example, it took me two days of searching to just figure out how to read element content from a file. For my small program it is definitely overkill. I think I'll stick with the plain text file :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CMS for plain text rblampain Linux - Software 3 12-14-2005 10:40 PM
not a plain text file wazza4610 Linux - Newbie 1 11-22-2005 04:20 AM
Plain Text Printing Messed Up milkycow Linux - Newbie 0 10-11-2004 02:27 AM
Plain text messages from Mozilla 1.4 arubin Linux - Software 1 07-13-2004 07:45 PM
Printing from lpr to plain text DoubleLetter Linux - General 2 07-19-2002 11:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration