commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <>
Subject [Digester] How to change when rules fire
Date Thu, 15 Sep 2005 05:02:04 GMT
Hi everyone,

I have a situation where I need to parse some XML that looks like this:

       <initList name="children" method="addChild">
         <listItem value="Andrew" />
         <listItem value="Michael" />

What I want to have happen is that for each <listItem> element 
encountered, I want to call this method of the top object on the stack:

   public void addInitList(String inMethod, String inName,
     String inValue);

...where the inMethod and inName parameters get their value from the 
parent <initList> element.  Here's what I've done:


     "addInitList", 3);
   digester.addCallParam("dependencies/dependency/initList", 0,
   digester.addCallParam("dependencies/dependency/initList", 1,
   digester.addCallParam("dependencies/dependency/initList/listItem", 2,

Now, this works, sort of... what actually happens is only the last 
<listItem> encountered triggers the call to addInitList().  And I'm not 
sure I see how to do otherwise,

One thought I had was to call a method when <initList> is encountered 
that would save the name and method attributes, then just write a 
separate rule for <listItem> to call a method that knows how to get 
those temporary values.  That would work I think, but the problem is 
that CallMethodRule only seems capable of firing at end(), and I would 
need it to fire at begin() in this case.  I didn't see one, but is there 
a way to tell a rule to fire at a different event trigger like this?  I 
suppose a custom rule would be one answer, but is there another way?

Assuming not though, can anyone give me some pointers as to how to 
modify the rules as written above to do what I need?  I'll keep at it, 
but so far I haven't figured it out.  Thanks all!

Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies

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

View raw message