正好看到,给个例子public class SampleDigester
{
  public void run() throws IOException, SAXException
  {    
    Digester digester = new Digester();    // This  method pushes this (SampleDigester) class to the Digesters
    // object stack making its method s available to processing rules.
    digester.push(this);    // This set of rules calls the addDataSource method and passes
    // in five parameters to the method.
    digester.addCallMethod ("datasources/datasource", "addDataSource", 5);
    digester.addCallParam("datasources/datasource/name", 0);
    digester.addCallParam("datasources/datasource/driver", 1);
    digester.addCallParam("datasources/datasource/url", 2);
    digester.addCallParam("datasources/datasource/username", 3);
    digester.addCallParam("datasources/datasource/password", 4);
    // This method starts the parsing of the document.
    digester.parse("datasource.xml");
  }
  // Example method called by Digester.
  public void addDataSource(String name,
                            String driver,
                            String url,
                            String userName,
                            String password)
  {
    // create DataSource and add to collection...
  }
}在上面的SampleDigester类中,每当匹配到 'datasources/datasource'时都会自动调用addDataSource()方法。addCallParam()方法将匹配到的数据项内容作为传入addDataSource()方法的参数。在addDataSource()方法中,你就可以创建具体的DataSouce并把它添加入你的DataSource集合中去。