日期:2014-05-17 浏览次数:20631 次
public class Test { private static Logger logger = Logger.getLogger(Test.class.getName()); public static Map dataBase=new HashMap();; /** * @param args * @throws SAXException * @throws IOException */ public static void main(String[] args) throws IOException, SAXException { Digester digester = new Digester(); digester.setValidating(false); digester.addRule("appconfig/dataBaseCfg", new MyRule("put",2)); digester.addRule("appconfig/dataBaseCfg", new CallParamRule(0,"id")); digester.addRule("appconfig/dataBaseCfg", new CallParamRule(1)); digester.parse(Test.class.getResourceAsStream("config.xml")); System.out.println(dataBase); } } class MyRule extends CallMethodRule{ public MyRule(String methodName,int param) { super(methodName, param); } @Override public void begin(Attributes attributes) throws Exception { digester.push(Test.dataBase); super.begin(attributes); } @Override public void end() throws Exception { super.end(); digester.pop(); } }
------解决方案--------------------
楼上+1