final String root= "root/";
final String out= "elementOut/";
final String in= "elementIn/";
final String id = "id";
final String NAME = "name";
String namespace = reg.getFilename();
final Digester digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate(root, HashMap.class);
digester.addCallMethod(root+ out, "put", 2);
digester.addCallParam(root+ out, 0, ID);
digester.addObjectCreate(root+ out, ArrayList.class);
digester.addCallMethod(root+ out + in, "add", 1);
digester.addCallParam(root+ out + in, 0, name);
digester.addCallParam(root+ out, 1, true);
Map<String, List<String>> map = digester.<Map<String, List<String>>> parse(reg
.getInputStream());
相应的 xml 将键映射匹配为字符串,将值匹配为字符串列表。
<root>
<elementOut id="key1">
<elementIn name="value1" />
</elementOut>
<elementOutid="key2">
<elementIn name="value1" />
<elementIn name="value2" />
</elementOut>
</root>