On Wed, 2004-04-14 at 10:40, Thyr wrote:
> Hello,
>
> I want to use digester to solve the following task:
>
> test.xml
> <?xml version='1.0' encoding='utf-8'?>
> <root>
> <a>content</a>
> <b>
> <a>deeper content</a>
> </b>
> <a>another content</a>
> </root>
>
> The code:
> Digester d = new Digester();
> d.addObjectCreate("root", Root.class);
> //match all "a"
> d.addSetRoot("*/a", "addA", "java.lang.String");
> Root root = (Root) d.parse(new File("test.xml"));
>
> and:
> public class Root {
> private String aA;
>
> public void addA(Object a) {
> System.out.println(a);
> }
> }
>
> The system.out tells me, the passed object is an Root-Object. But I need
> to have the content.
> Where is my mistake. What can I do?
You need another ObjectCreate rule, to create an instance of "A":
digester.addObjectCreate("*/a", A.class);
Without this, the object stack is only ever 1 deep (the Root instance),
and the SetRoot rule then tries to pass the top object (a Root instance)
to the bottom object on the stack (itself!).
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]