File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Difference between Properties file and .xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Difference between Properties file and .xml file" Watch "Difference between Properties file and .xml file" New topic
Author

Difference between Properties file and .xml file

samir vasani
Ranch Hand

Joined: Nov 24, 2010
Posts: 59
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

Joined: Jul 28, 2010
Posts: 153

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

Joined: Nov 24, 2010
Posts: 59
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

Joined: Jul 28, 2010
Posts: 153

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

Joined: Nov 24, 2010
Posts: 59
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Properties file and .xml file
 
Similar Threads
Multi Process Configuration
ResourceBundle and Properties
is this XML???
XML parsers
Bound & Constraints properties