Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 35242 invoked from network); 17 Sep 2005 00:28:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Sep 2005 00:28:04 -0000 Received: (qmail 33258 invoked by uid 500); 17 Sep 2005 00:27:59 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 32944 invoked by uid 500); 17 Sep 2005 00:27:57 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 32927 invoked by uid 99); 17 Sep 2005 00:27:57 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2005 17:27:57 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [210.86.15.158] (HELO avmta3-rme.xtra.co.nz) (210.86.15.158) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2005 17:28:06 -0700 Received: from mta4-rme.xtra.co.nz ([210.86.15.140]) by avmta3-rme.xtra.co.nz with ESMTP id <20050917002747.NOAD7577.avmta3-rme.xtra.co.nz@mta4-rme.xtra.co.nz>; Sat, 17 Sep 2005 12:27:47 +1200 Received: from [10.1.1.5] ([219.89.109.33]) by mta4-rme.xtra.co.nz with ESMTP id <20050917002747.CLJA5449.mta4-rme.xtra.co.nz@[10.1.1.5]>; Sat, 17 Sep 2005 12:27:47 +1200 Subject: Re: [Digester] How to change when rules fire From: Simon Kitching Reply-To: skitching@apache.org To: fzlists@omnytex.com Cc: Commons User In-Reply-To: <4329004C.4000803@omnytex.com> References: <4329004C.4000803@omnytex.com> Content-Type: text/plain Date: Sat, 17 Sep 2005 12:27:59 +1200 Message-Id: <1126916879.4735.15.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Thu, 2005-09-15 at 01:02 -0400, Frank W. Zammetti wrote: > Hi everyone, > > I have a situation where I need to parse some XML that looks like this: > > > > > > > > > > > What I want to have happen is that for each 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 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 > encountered triggers the call to addInitList(). No, it isn't the last that's triggering the call. The method call always happens once for every match of the CallMethodRule. You've specified a pattern of "dependencies/dependency/initList" for that rule, so it fires once for each initList element found, *not* for each listItem. When a CallParamRule fires it just stores its value away for use when the method call actually happens, which is why you see the last listItem's value as the parameter to the call. Your later email describes a solution where the initlist object effectively has a list of listItem objects which are added to the parent initList as the listItem elements are encountered. The initList object then has a method which adds all of its child listItem objects to the root object after they have been processed. You describe this as "not very elegant" but I think it's fine. The xml is clearly indicating that listItem objects are children of an initList object, and this solution implements exactly that. The only thing that could possibly be called "not very elegant" is the last step where the listItems are added to some root object (effectively "denormalising" the data structure) rather than simply adding the InitList object to its parent, leaving the data in a structure which echoes the xml layout. You do mention "resetting" the initList's list of children "for the next group" but I don't think this is necessary is it? When the next tag is encountered, a new InitList object should be created which will of course have an initially empty list of children. Cheers, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org