commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Keese <>
Subject Re: [digester] how to use digester with a class hierarchy
Date Wed, 19 May 2004 04:43:45 GMT
Thanks Simon!

> All the existing Digester object creation options
> (ObjectCreateRule, FactoryCreateRule) create the target object when the
> opening xml tag is found.

I see. In that case, I need to create the Text object when the <text>
tag is encountered. The question is, how do I save the information that
appears before the <text> tag?

<x>10</x> <y>20</y>
<text> Hello world </text>

I suppose that I could have some kind of dummy ComponentBuilder class
which would sit at the root of the stack and save the x/y value.
Something like this, maybe:

digester.addObjectCreate("component", ComponentBuilder.class);
digester.addSetNext("component/x", "addX"); // save x in ComponentBuilder
digester.addSetNext("component/y", "addY"); // save y in ComponentBuilder
digester.setTopRule("component/text", "setXY"); // initialialize Text.x
and Text.y
// from values saved in ComponentBuilder
digester.addSetNext("component/text", "setComponent"); // stores Text
obj in ComponentBuilder obj

ComponentBuilder foo = (ComponentBuilder) digester.parse();
Component realResult = foo.getComponent();

It's a bit ugly, but not so bad.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message