commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [Digester 1.5] Pattern matching screwed me up
Date Sun, 29 Feb 2004 00:54:16 GMT
On Sun, 2004-02-29 at 13:11, Martin Kersten wrote:
> Hi maillist,
>   after I've tried for hours to get my simple XML shema working 
> (due to bad documentation if you ask me). I nearly give up.

Ummm .. you aren't likely to win many friends on this list with comments
like that. You're asking for help, yet criticising the *volunteers* who
wrote the software for not putting enough of their *unpaid* time into
the project?

I'm not sure why I'm answering this at all...

> My problem? Well I want to use selfcontainment. Given you 
> an example: 
> <a><a>
>     <b></b>
> </a></a>
> So whats the problem?
> First of all this wont work:
> digester.addObjectCreate("a",A.class);
> digester.addObjectCreate("b",B.class);  
> digester.addSetNext("a/a","add");
> digester.addSetNext("a/b","addB");
> Why does this wont work? Well took me an hour
> to figure it out (thanks for the hidden java doc documentation
> -why not pointing it out in a seperate documentation file? Like
> everyone does?)
> Ok here you go, just add an */ to match everything...
> digester.addObjectCreate("*/a",A.class);
> digester.addObjectCreate("*/b",B.class);  
> digester.addSetNext("*/a/a","add");
> digester.addSetNext("*/a/b","addB");
> Looks right, doesn't it? Well not for digester, it seams! Since 
> */a/a is a closer pattern match it seams, adding it is just more 
> important then creating the object first (who cares null pointer?!).
> Ok therefore lets add a hack:
> digester.addObjectCreate("*/a",A.class);
> digester.addObjectCreate("*/b",B.class);  
> digester.addObjectCreate("*/a/a",A.class);
> digester.addObjectCreate("*/b/a",B.class);  
> digester.addSetNext("*/a/a","add");
> digester.addSetNext("*/a/b","addB");
> Works! But halt, bad karma... . If you have something
> like setProperties("*/a","id","id"); You can collapse right
> now. Since */a is not as exact as */a/a it would not be called
> right out of the box (setNext will be called first). So what to do? 
> Adding another setProperties("*/a/a","id","id")? 
> Would fix it!
> Crazy. It seams I've missed an important information. Can someone 
> shade some light? I dont want to blaim digester but I am trying 
> for hours. I wanted to save time but who could know that 
> digester hates tags containing itself. (anyone like trees?). 
> I can not imagen that simple trees are beyond the caps of digester.
>  So I am thinking the fault is just on my side. 
> So please, tell me what am I doing wrong?!

> PS: Tried for more then four hours fooling around with test cases, looking 
> for the internet and debugging the digester api. I am just a little, well lets 
> call it disapointed... .

You want the following behaviour:
* For an "a" element at the top level, create an object but don't try to
add it to a parent object.
* For "a" elements elsewhere, create an object and add it to a parent
* For "b" elements elsewhere, create an object and add it to a parent

So I think this should do:

Note that because pattern "a" overrides pattern "*/a", digester doesn't
(wrongly) try to call "add" for the top-level "a" element.

And when you're done, feel free to write a user manual and submit it for
inclusion into the project...

[of course the code above is not tested....]



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

View raw message