(原始答案)
使用简单的Rule为模式“ furniture / *”创建Digester,该规则将第二个参数添加到对begin方法的每次调用中,并将其粘贴到您选择的集合中(获取所有列表的列表,仅获取所有列表的集合)唯一名称).
(编辑)
从头开始,它有点复杂.
这有效:
public class App
{
final static Rule printRule = new Rule() {
public void begin(String namespace, String name,
Attributes attributes) throws Exception {
System.out.println(name);
}
};
public static void main( String[] args ) throws IOException, SAXException
{
InputStream instr = App.class.getResourceAsStream("/sample.xml");
Digester dig = new Digester();
dig.setRules(new RulesBase(){
public List match(String namespaceURI, String pattern) {
return Arrays.asList(printRule);
}
});
dig.parse(instr);
}
}
此特定示例将打印所有元素名称,包括根家具元素.我将它留给您,以根据您的需要调整match()方法.