You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hartmut Bernecker <h....@dhw.de> on 2001/06/06 12:57:57 UTC

Need your help --> Digester class

Hi,

I want use the Digester class to populate some objects with XML-Data.
The Properties of the objects have not identical names to the
XML-Attributes.
Therefore I need a mapping.
Am I right, when I search for a solution with that statement:

**************************************************
digester.addSetProperty("test", "email", "mail");
**************************************************

Where "test" is the XML-element, "email" is the Property of my object on
top of the stack, and "mail" is the XML-attribute within the "test"-Tag
to be evaluated?

The XML-Source snippet is:

********************************
<test mail="h.bernecker@dhw.de"/>
********************************

Here is the debug-protocol when parsing the XML with the digester:

***********************************************************************************
Set de.dhw.asim.components.benutzer.UserDaten property null to
h.bernecker@dhw.de

***********************************************************************************

Why is the property null?????
What make I wrong??

_________________________________________
Hartmut Bernecker
Druckhaus Waiblingen
Siemenstrasse 10
D-71332 Waiblingen, Germany
http://www.dhw.de/

Re: Need your help --> Digester class

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 6 Jun 2001, Hartmut Bernecker wrote:

> Hi,
> 
> I want use the Digester class to populate some objects with XML-Data.
> The Properties of the objects have not identical names to the
> XML-Attributes.
> Therefore I need a mapping.
> Am I right, when I search for a solution with that statement:
> 
> **************************************************
> digester.addSetProperty("test", "email", "mail");
> **************************************************
> 
> Where "test" is the XML-element, "email" is the Property of my object on
> top of the stack, and "mail" is the XML-attribute within the "test"-Tag
> to be evaluated?
> 
> The XML-Source snippet is:
> 
> ********************************
> <test mail="h.bernecker@dhw.de"/>
> ********************************
> 
> Here is the debug-protocol when parsing the XML with the digester:
> 
> ***********************************************************************************
> Set de.dhw.asim.components.benutzer.UserDaten property null to
> h.bernecker@dhw.de
> 
> ***********************************************************************************
> 
> Why is the property null?????
> What make I wrong??
> 

The "set property" rule is still going to expect the property names  to
match.  One thing you might consider is using a BeanInfo class associated
with your bean so that the standard JDK introspection code will work.

Another approach would be to consider modifying your XML structure to look
like this if you can:

<test>
  <mail>h.bernecker@dhw.de</mail>
</test>

Then, you can use the "call method" rule to process it:

digester.addCallMethod("test/mail", "setEmail", 0);

If you can't do this, you will need to write a custom Rule.

> _________________________________________
> Hartmut Bernecker
> Druckhaus Waiblingen
> Siemenstrasse 10
> D-71332 Waiblingen, Germany
> http://www.dhw.de/
> 

Craig