IntelliJ Java IDE
The moose likes XML and Related Technologies and the fly likes What do i choose??? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "What do i choose???" Watch "What do i choose???" New topic
Author

What do i choose???

Marilyn Monickam
Ranch Hand

Joined: Jun 05, 2001
Posts: 66
Hi
Suppose i want to store 2 attributes
say,name and age of a person ,do i go for an XML document or a properties file?Depending on what do I choose?
Thanks
Marilyn
Ambrose Tati
Ranch Hand

Joined: Oct 03, 2000
Posts: 55
Hi Marilyn,
I find XML very cool and hot. But in your case I think and XML document would be an overkill. A property file would be more than fine.
Cheers
Ambrose Tati
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
I agree with Ambrose - unless you mean you'll store the name and age of more than one person. Then, there's no obvious logical way to organize the data in a properties file - but it's easy in XML.


"I'm not back." - Bill Harding, Twister
Marilyn Monickam
Ranch Hand

Joined: Jun 05, 2001
Posts: 66

Thanks Ambrose and Jim.
Let us consider another case where i have to store the information of a 100 people .In that case why do you think an XML file would be a better choice?
I am new to XML
Marilyn

Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Well, a property file requires you to have a unique name for everything, and allows you to map each name to a unique element. I suppose that if you wanted to just store name and age, you could use a property file:

But already there are several problems. The names must be unique. They can't have spaces in them, so I replaced spaces with underscores. And most importantly, what if I want to store another bit of data, like date of birth? Where do I put it? The properties file is a lousy way to manage this much data. But it's easy with XML:

Or if you prefer:


[This message has been edited by Jim Yingst (edited July 13, 2001).]
Marilyn Monickam
Ranch Hand

Joined: Jun 05, 2001
Posts: 66
Jim ,

I understand that the properties file is a lousy way of storing very large data since you need a unique name for each attribute you store
okay forget a property file and consider a simple text file
What if i get the data stored like this?
name =Joe Smith
age =24
birthdate=9/12/76
name=Bill Evans
age=27
birthdate=10/30/79
name=Sara Miller
age =26
birthdate=4/12/77
and then introduce some parsing logic to retrieve data?
are there any more advantages of XML apart from readability?
Marilyn
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5781
Okay, you invent your own format and parse the data using a home-grown parser. What happens when you want to send this data to a third-party client? Since this is a nonstandard format, you will also have to send them the parser, the document structure and all the other repertoire in order for them to make sense out of this data. What happens if you change the format, say after one year? See where I'm going?
If you use XML instead of the flat file, you can be rest assured that everyone else who is XML-aware can readily accept and process your file.
Having said that, I can tell you a number of drawbacks with the text format that you are using. For example, it is quite hard to represent hierarchically organized data. Even harder to represent relations between them. If you decide to find your way around these limitations, you may on your way trying to reinvent the XML


------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.


Open Group Certified Master IT Architect.
Sun Certified Architect(SCEA).
Marilyn Monickam
Ranch Hand

Joined: Jun 05, 2001
Posts: 66
Thanks Ajit

I am convinced now.
Thanks
Marilyn
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Two more important advantages of using XML here: 1) A lot of the work has already been done for you - e.g. rather than writing the parsing code yourself from scratch, you can take advantage of existing parsing modules, and customize them to your needs. 2) XML is relatively hot and trendy right now, so in terms of your personal marketability in IT, it can't hurt to have some XML experience on your resume.
 
IntelliJ Java IDE
 
subject: What do i choose???
 
Threads others viewed
do they ask in exam which error code says what
What next?
how to choose fold
Kind of error on loading a table rows in a web
Webservice vs JMS
developer file tools