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="[EMAIL PROTECTED]"/>
> ********************************
> 
> Here is the debug-protocol when parsing the XML with the digester:
> 
> ***********************************************************************************
> Set de.dhw.asim.components.benutzer.UserDaten property null to
> [EMAIL PROTECTED]
> 
> ***********************************************************************************
> 
> 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>[EMAIL PROTECTED]</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


Reply via email to