Tuesday, February 21, 2006

Properties file or XML File

While working on Java Projects we usually come to question whether to use properties file or to use XML files for reading configuration information.

Before we consider what solution should be used, first let's see what kind of the configuration data is involved.

Configuration data are range from simpler items like server urls, schema name, database environment, mailing servers, etc. This kind of data can be classified as name=value pair. No relationship or hierarchy exist between them.

The other cases of configuration data that might be used within project contains relationship within data elements. One of the example of such data is struts-config.xml. For this kind of data they will be more or less stored as Java Objects.

Once we made the classification decision is simple.

Use properties file for configuration data which is flat in nature. Data elements does not contain any relationship or hierarchy. Using XML file to store will involve parsing overhead without any significant advantage.

XML file usage is justified only when we are going to create Java Objects out of config data elements having relationship between them.

One of the pitfalls using XML file to store config file is to go on overkill and start integrating logic in XML tags. Make sure that it is only config data and you are not actually programming in XML.
Post a Comment