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] 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?

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

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.

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