Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Properties file and .xml file

 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My question is what is the difference between properties file and .xml file.?
And when should we use these file?
 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowledge .properties files are used to have key and value pair. But xml files are entirely different thye have their own standard. xml is mainly used to exchage information between applications like integration
 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malatesh Karabisti wrote:As per my knowledge .properties files are used to have key and value pair. But xml files are entirely different thye have their own standard. xml is mainly used to exchage information between applications like integration

Can you explain it with an example?
 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
properties file looks like this
key1=Value1
key2=Value2

where are xml looks like this for example web.xml
<web-app>
<display-name>application</display-name>
<description>AnApplication</description>
<context-param>
<param-name>context-root</param-name>
<param-value>Rootvalue</param-value>
</context-param>
</web-app>
 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malatesh Karabisti wrote:properties file looks like this
key1=Value1
key2=Value2

where are xml looks like this for example web.xml
<web-app>
<display-name>application</display-name>
<description>AnApplication</description>
<context-param>
<param-name>context-root</param-name>
<param-value>Rootvalue</param-value>
</context-param>
</web-app>


Yeah thats fine with me
here in .xml can we use<param-name>key1</param-name>
<param-value>value</param-value>
which can makes both .xml and .properties working same???
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no. Your example is, I think, based on a slightly simplistic appreciation of what an XML file is. You could, for example, add validation of the values you using in your XML file itself (by defining a schema), so XML supports functionality above and beyond that provided by properties files.

If you need simple key/value pairs properties files are the way to go.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to amplify what Paul said:

You should have seen some of the early approaches to configuring Java servlets! JRun had dozens of properties files with complicated names in an attempt to handle a complex situation with the Properties logic.

Xml (such as servlets web.xml) may be a bit of a pain to learn but it is a programmer's salvation for complex configuration.

Bill

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic