yes, this makes sense. i may be on the verge of seeing how it might work for what i am trying to do.
Bill Keese wrote:
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- rich coco [EMAIL PROTECTED] 781.736.1200 x165 Starbak Inc. 29 Sawyer Rd. One University Office Park Waltham, MA 02453
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
