commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [Digester] Supporting mixed content
Date Sat, 05 Jan 2002 22:02:25 GMT
On Friday, January 4, 2002, at 01:37 AM, Scott Sanders wrote:

> Hi all,
> I am trying to use Digester in a situation where some elements have
> mixed content.  For example:
> <tag name="text">Beginning effective <tag
> name="variableRef">EffectiveDate</tag>, the new policy will be in
> effect.</tag>
> So, currently Digester just appends the characters() method to the body
> text and then uses it at the endElement() method.  The problem is that I
> need the "Beginning effective " and the ", the new policy..." are
> actually two specifically different calls to some method, like
> addNode().  I know it sounds a little like DOM, but that is what I need
> at the moment.
> So, how do I accomplish this?  I propose changing the characters()
> method to call rules bodyText() method.  To prevent breakage, then I
> need the default Rule class to append these together and then use it.

one possible approach might be to use a list (or something) of 
StringBuffers. the idea is that you create a new StringBuffer when a new 
piece of mixed context begins.

to use your example above, digester would begin by create a StringBuffer. 
'Beginning effective' would be appended. a list containing the 
StringBuffer would be then pushed onto the body text stack. it'll be 
popped off when the inner tag element is finished. digester would then 
create a new StringBuffer, and add it to the end of the list. ' the new 
policy will be in effect.' would then be appended to last StringBuffer in 
the list. when the outer tag element is finished, digester concatinates 
the contents of the buffers and calls bodyText on the rules with the 
result. the list of StringBuffers could be presented as a property.

it's a little convoluted but maybe this would do what you want without 
having to change the Rule interface.

- robert

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

View raw message