commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: [digester] how to parse node trees
Date Fri, 30 Apr 2004 02:17:07 GMT
On Fri, 2004-04-30 at 05:51, José Antonio Pérez Testa wrote:
> Hi Juergen,
> apart from corrections donwside, you have to push an object to the 
> Digester stack 
[...]
> That is because the SetNext rule pops the element from the stack, so if  
> you start up with nothing you end up with nothing.

Hi Juergen,

Jose is right; if you have <node> as the root element of your document,
and a SetNextRule with pattern "*/node" then when that rule fires it
will "peek" at the second-to-top element on the object stack, and try to
call the appropriate method on it passing the top object. But there
won't be a second-to-top object so an exception will be generated. 

SetNextRule doesn't actually pop anything from the stack, it just peeks
at the top and second-to-top objects. But when the stack is only one
object deep....

The easiest solution for this is (as Jose says) to manually push an
object onto the stack before parsing starts. This object must have an
addNode(Node) method - which probably means simply pushing a Node object
onto the stack to behave as the "root" of the generated tree.

An alternative is to create "special case" rules so that the root
element is treated differently (avoid the SetNextRule). Because rules
without wildcards take precedence over rules with wildcards this isn't
too hard to do (see the RulesBase javadoc for more info).

> >
> //digester.addObjectCreate("node",Node.class);
> digester.addObjectCreate("*/node",Node.class);

Yep, I second Jose on this too.


Regards,

Simon 


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