Skip to main content

User-Friendly XML Config

Posted by tomwhite on October 27, 2005 at 2:49 PM PDT

There's been a bit of a backlash against XML config files lately. The Ruby On Rails community has a crisp putdown: avoid "doing XML sit-ups". And the arrival of Java annotations in J2SE 5.0 seemed to muddy the waters somewhat - do I still need to use XML config? Well yes, they are really designed for different things (as Dennis Sosnoski points out).

So if XML config files are going to continue to be a part of a Java developer's life, it's worth making them a little easier to work with. A trick that I noticed in one of Nutch's XML config files was the use of an xml-stylesheet processing instruction to render the file in a nice table when viewed in a browser:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="nutch-conf.xsl"?>

The stylesheet, nutch-conf.xsl, simply transforms the configuration XML into an HTML table. You can view the result here.
It's a technique that is used elsewhere - quite a few RSS feeds do it, for example, such as the BBC.
In the context of Java XML config, I think it's a good way to make large config files more approachable. If you're new to a project it's easy to open the file in a browser and quickly scan through it.
It's certainly easier than grokking the XML. So if you're writing an XML config file - please add some style!

Related Topics >>