commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Keese <bi...@tech.beacon-it.co.jp>
Subject Re: [Digester] basic usage problem. Help me understand the stack.
Date Tue, 27 Jul 2004 02:14:17 GMT

>>it does not seem to me the "*/part" type of pattern will work.
>>this approach does not keep the correspondence between a <part> strucuture
>>and its parent container(s).
>>    
>>
I might be wrong, but I think that this is just a simple
misunderstanding. Apparently, you are thinking that

digester.addObjectCreate("*/part", "mypackage.Part");

will create a flat list of parts, rather than a (hierarchical) tree. But
that's not the case.

> // Set up the digester
> Digester digester = ...;
> digester.addObjectCreate("*/part", "mypackage.Part");
> digester.addSetProperties("*/part");
> digester.addSetNext("*/part", "addPart", "mypackage.Part");
>
> // Push a dummy Part onto the stack to collect all the top-level parts
> Part dummy = new Part();
> digester.push(dummy);

At this point, stack=(dummy).

>
> // Parse the XML document
> digester.parse(...);

> 1 <parts>
> 2 <part id="1">
> 3 </part>
> 4 <part id="2">
> 5 <part id="2a">
> 6 </part>
> 7 </part>
> 8 </parts>


When you call parse, here's what digester does as it processes each line
of the input XML file:

Line 2:
- stack.push(new Part(id=1))

stack = (dummy, part#1)

Line 3:
- dummy.addPart(stack.pop()) <-- add part#1 as child of dummy

stack = (dummy)

Line 4:
- stack.push(new Part(id=2))

stack = (dummy, part#2)

Line 5:
- stack.push(new Part(id=2a))

stack = (dummy, part#2, part#2a) <-- hierarchy is correct, right?

Line 6:
- part#2.addPart(stack.pop()) <-- this makes part#2a a child of part#2

stack = (dummy, part#2)

Line 7:
- dummy.addPart(stack.pop()) <-- add part#2 as child of dummy

stack = (dummy)

Does that make sense?

Bill

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message