On Tue, 4 Dec 2001, James Strachan wrote:

> Date: Tue, 4 Dec 2001 16:43:56 -0000
> From: James Strachan <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> To: Jakarta Commons Developers <[EMAIL PROTECTED]>
> Subject: [digester] setting attributes & text content on the same
>     object...
>
> Has anyone found any ways to do the following in digester.
>
> Imagine the folllowing class
>
> public class Param {
>     public void setName(String name);
>     public void setValue(String name);
> }
>
> And I want to parse XML like this...
>
>     <param name="foo">bar</param>
>
> And I want the text value of the <param> element to be associated with the
> 'value' property of the Param.
>
> Then in Digester I'm doing this...
>
>         String path = "foo/param";
>         addObjectCreate( path, paramClassName, "className" );
>         addSetProperties( path );
>         addCallMethod( path, "setValue", 0 );
>         addSetNext( path, "addParam", paramClassName );
>
> Which works but the value is never set. Is anyone aware of any way around
> this problem? I'm guessing its a current digester limitation.
>
> I know I can parse this fine...
>
>
>     <param name="foo" value="bar"/>
>

This is courtesy of the (relatively) new SetPropertyRule -- Jason van Zyl
ran into a need for this one, and suggested this approach.  We could
probably extend SetPropertyRule to work they way you want by grabbing the
value from the body content if there is no "value" argument.

> Which is a work around for now - I'm just wondering if there's a way of
> using attributes and text content for the same object & element in digester.
>
> James
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to