commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [digester] help with multi-argument constructor
Date Mon, 26 May 2003 13:28:41 GMT
On Monday, May 26, 2003, at 06:09 AM, Simon Kitching wrote:

> On Sat, 2003-05-24 at 13:30, Christopher Bare wrote:
>> Hi,
>> I'm trying to parse XML something like this:
>>   <user>
>>     <id>1</id>
>>     <name>chris</name>
>>   </user>


> Still, it would be nice to be able to construct an object with
> parameters based upon nested tags. Anyone else out there got any
> ideas????

i have a couple of ideas. (unfortunately i'm busy at the moment and so 
probably won't have time to code either of them any time soon.)

perhaps the object could be created and pushed onto the stack when the 
rule's body method is called and then removed (as per usual) when the end 
method is called. i think that (given some careful ordering), the object 
will be on the stack long enough for rules that take their effect in the 
end method (for example setNextRule) to act on it. i think that a rule 
like this should be straight forward to create and would satisfy many use 
cases (including the example Christopher gives).

a more and complex possibility would be to create rules that work together 
to call the constructor when all the parameters have been assembled. so, 
for the above example, the object would be constructed after the name 
element body content has been parsed. this would be more difficult to code 
and could not cope with XML maps whereby absence of child element implies 
that a null should be passed into the constructor.

of course, Christopher could relatively easily solve his specific problem 
by creating his own rule.

- robert

View raw message