package com.example.demo2;
import java.io.File;
import org.apache.commons.digester.Digester;
public class DigesterDriver {
public static void main(String[] args) {
try {
Digester digester = new Digester();
File input = new File("E:\\MyProjects\\Workspace\\DigesterDemo\\src\\com\\example\\demo2\\example.xml");
File input2 = new File("E:\\MyProjects\\Workspace\\DigesterDemo\\src\\com\\example\\demo2\\example2.xml");
Catalog2 c = new Catalog2();
digester.push(c);
digester.setValidating(false);
digester.addObjectCreate("catalog/hi/book", Book2.class);
digester.addBeanPropertySetter("catalog/hi/book/author", "author");
digester.addBeanPropertySetter("catalog/hi/book/title", "title");
digester.addSetNext("catalog/hi/book", "addBook" );
digester.parse(input);
digester.push(c);
digester.parse(input2);
System.out.println(c.getBooks().size());
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
鍏朵腑錛岀孩鑹查儴鍒嗘槸鍚庢潵鍔犲叆鐨勶紝浠旂粏闃呰浜?jiǎn)struts鐨勯儴鍒嗕唬鐮侊紝鍙戠幇浜?jiǎn)杩欎釜閿欒銆傜綉涓婂榪欎釜浠嬬粛姣旇緝?yōu)畱锛屽彲鑳芥垜杩欎釜闂姣旇緝寮辨櫤鍚с俿truts鐨勪唬鐮佺墖孌靛涓嬶細(xì)
// Configure the Digester instance we will use
Digester digester = initConfigDigester();
// Process each specified resource path
while (paths.length() > 0) {
digester.push(config);
String path = null;
int comma = paths.indexOf(',');
if (comma >= 0) {
path = paths.substring(0, comma).trim();
paths = paths.substring(comma + 1);
} else {
path = paths.trim();
paths = "";
}
if (path.length() < 1) {
break;
}
this.parseModuleConfigFile(prefix, paths, config, digester, path);
}

]]>