Load/Read XML Configuration Files Using Apache Digester

There would no developer in this world who haven’t heard or used XML in his daily usage. When it really comes to developing a new product , Creating a Soap message or Communicating over ESB we always have to think about XML. Here i’m providing an efficient approach other then SAX and DOM that can easily setup ypur project configuration in Minutes by creating configuration objects from xml

Apache Digestor is One such utility which was create for a purpose to make XML to Dataobject Conversion very easy and straight forward

Digestor as the name suggests consumes XML and Created Javaobjects which represent the Configuration

Code that can do this is pretty simple and straight forward

package com.linkwithweb.configuration.utilities;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;

import com.linkwithweb.configuration.dataobject.ReplayMagix;

* @author ashwin kumar
public class ReplayMagixDigestor {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
ReplayMagixDigestor xmlDigest = new ReplayMagixDigestor();

public void digest() {
try {
// Create Digester using rules defined in academyRules.xml
Digester digester = DigesterLoader.createDigester(this.getClass()

// Parse academy.xml using the Digester to get an instance of
// Academy
ReplayMagix a = (ReplayMagix) digester.parse(this.getClass()



} catch (Exception e) {


As you see in the code there is a XML which i want to load into configuration object and there is another xml which defines how i should load .

My Sample XML Definition is (replay-magix.xml)

<?xml version=”1.0″?>
<replaymagix name=”TEST”>
<pathelement location=”lib/” />
<pathelement path=”lib2/test.jar” />


And Here is my Rule which defines how to Load it (replayRules.xml)

<?xml version=”1.0″?>
<pattern value=”replaymagix”>
classname=”com.linkwithweb.configuration.dataobject.ReplayMagix” />
<set-properties-rule />
<pattern value=”classpath”>
classname=”com.linkwithweb.configuration.dataobject.Classpath” />

<pattern value=”pathelement”>
classname=”com.linkwithweb.configuration.dataobject.PathElement” />
<set-properties-rule />
<set-next-rule methodname=”addPathElement” />

<set-next-rule methodname=”setClasspath” />

<pattern value=”debug-point”>
classname=”com.linkwithweb.configuration.dataobject.DebugPoint” />
<bean-property-setter-rule pattern=”classname” />
<bean-property-setter-rule pattern=”interfacename” />
<bean-property-setter-rule pattern=”parentname” />
<bean-property-setter-rule pattern=”methodname” />
<bean-property-setter-rule pattern=”point” />

<set-next-rule methodname=”addDebugPoint” />

If you need working and mavenized code contact ashwin@linkwithweb.com