commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Hauser <>
Subject [Digester] HashMap on top of stack
Date Tue, 10 Feb 2004 13:55:42 GMT
Hi list

I'd like to use Digester to parse an XML file. The root element 
('definitions') should correspond to a HashMap. This HashMap should 
contain key/value pairs, whereas the value is a bean of type 
DefinitionBean and the key is stored within the DefinitionKey.

Here what I have so far:

   Digester d = new Digester();
   d.addObjectCreate("definitions", HashMap.class);
   d.addObjectCreate("definitions/definition", DefinitionBean.class);
   d.addBeanPropertySetter("definitions/definition/key", "key");

   // And this stuff here isn't working of course,
   // but shows maybe what I'd like to do.
   DefinitionBean bean = (DefinitionBean) d.pop();
   HashMap hashMap = (HashMap) d.pop();
   hashMap.put(bean.getKey(), bean);

   HashMap map = (HashMap) d.parse(getTestXmlReader());

When the definitions/definition tag ends I'd like to do something like
hashMap.put(bean.getKey(), bean)
whereas bean is of type DefinitionBean. The DefinitionBean is on top of 
the stack and below the HashMap. Then of course the DefinitionBean 
should be removed from stack for the next to come.

I don't see a way to do that and would be very happy for every hint on that.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message