Вот рабочий пример:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.commons.digester3.Digester;
import org.xml.sax.SAXException;
public class SampleDigester {
public void run() throws IOException, SAXException {
Digester digester = new Digester();
digester.addObjectCreate("ParentChildren", HashMap.class);
digester.addCallMethod("ParentChildren/ParentChild", "put", 2);
digester.addCallParam("ParentChildren/ParentChild/Parent", 0);
digester.addCallParam("ParentChildren/ParentChild/Child", 1, 0);
digester.addObjectCreate("ParentChildren/ParentChild", ArrayList.class);
digester.addObjectCreate("ParentChildren/ParentChild/Child", StringBuffer.class);
digester.addCallMethod("ParentChildren/ParentChild/Child", "append", 1);
digester.addCallParam("ParentChildren/ParentChild/Child", 0);
digester.addSetNext("ParentChildren/ParentChild/Child", "add");
Object result = digester.parse("file:///path/to//input.xml");
System.out.println(result);
}
public static void main(String[] args) {
try {
new SampleDigester().run();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Файл input.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<ParentChildren>
<ParentChild>
<Parent>foo</Parent>
<Child>bar</Child>
<Child>bar1</Child>
<Child>bar2</Child>
<Child>bar3</Child>
</ParentChild>
<ParentChild>
<Parent>fooo</Parent>
<Child>barr</Child>
<Child>barr1</Child>
<Child>barr2</Child>
<Child>barr3</Child>
</ParentChild>
</ParentChildren>
И вывод: {foo=[bar, bar1, bar2, bar3], fooo=[barr, barr1, barr2, barr3]}
Я использовал это документация