I thought I'd post to let anyone readint his know that I did find a solution, although it's not truly a Digester-based solution (in a way), and not nearly as elegant as I was hoping for... but it *does* have one important virtue: IT WORKS!!

My rules now look like this:

  digester.addCallMethod("dependencies/dependency/initList/listItem",
    "addInitListTemp", 1);
  digester.addCallParam("dependencies/dependency/initList/listItem", 0,
    "value");
  digester.addCallMethod("dependencies/dependency/initList",
    "addInitList", 2);
  digester.addCallParam("dependencies/dependency/initList", 0,
    "method");
  digester.addCallParam("dependencies/dependency/initList", 1,
    "name");

The addInitListTemp() method now adds the <listItem> elements to a temporary array. Then, when the rule for the <initList> element fires (at the end), which is after the temporary array has been all built up, I can then take that array and do what needs to be done with it, and reset the temporary array to empty so another group can be dealt with if need be.

Like I said, not very elegant in my book, but effective. I'd still love to hear if anyone has a more "proper" way of accomplishing this, if for nothing else than a learning experience now, but I am all set at the moment. Thanks!

Frank

Frank W. Zammetti wrote:
Hi everyone,

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

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

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:

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

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
http://www.omnytex.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to