commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thyr" <Thyr...@compuserve.de>
Subject Re: [digester] addSetRoot and wildcards
Date Thu, 15 Apr 2004 07:57:08 GMT
Much Thanks!
I added the rule as you told me:
 d.addObjectCreate("*/a", A.class);
And additional
 d.addCallMethod("*/a", "setAA", 0);
The argument "java.lang.String" for the addSetRule is not longer needed.

Now it works fine.
Kind Regards
Reidar

-----Urspr√ľngliche Nachricht-----
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


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