To put some real code to the task of learning JDOM, let me introduce the PropsToXML class. This class is a utility that takes a standard Java properties file and converts it to an XML equivalent. Many developers out there have requested a means of doing exactly this; it often allows legacy applications using properties files to easily convert to using XML without the overhead of manually converting the configuration files.

Java Properties Files

If you have never worked with Java properties files, they are essentially files with name-value pairs that can be read easily with some Java classes (for instance, the java.util.Properties class). These files often look similar to Example 7-1, and in fact I’ll use this example properties file throughout the rest of the chapter. Incidentally, it’s from the Enhydra application server.

Example 7-1. A typical Java properties file

# Properties added to System properties

# sax parser implementing class

# Properties used to start the server

# Class used to start the server

# initial arguments passed to the server (replace command line args)

# Classpath for the parent top enhydra classloader

# separator for the classpath above

No big deal here, right? Well, using an instance of the Java Properties class, ...

Get Java and XML, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.