hi kevin

i don't think that you're missing anything here. betwixt only allows all or nothing.

i suppose that it would be possible to replace the simple attributeForPrimitives with some sort of strategy interface which would allow the user to specify a custom policy about which properties should map to attributes and which to elements. maybe i'll add this to the to do list but we're focused on pushing towards that alpha release so don't expect it to be done any time soon.

if it's a real itch then maybe you might want to contribute a patch to provide this functionality. if so, i'll certainly provide whatever help i can.

- robert

On Wednesday, January 8, 2003, at 12:05 AM, Kevin Ross wrote:

First, I'm new to Betwixt, but by no means new to the Digester.  I've
used the Digester successfully for several projects.

I'm having a problem.  I cannot figure out how to have my existing xml
be read/written properly (without a betwixt file), when my XML root
element already contains an attribute @id and also has (what Betwixt
classifies as a 'primitive') an element <name>, which is a String.  For
example:

<customer id="111">
       <name>XYZ LLC</name>
</customer>

Tester:

BeanReader reader = new BeanReader();
XMLIntrospector x =  new XMLIntrospector();
            x.setElementNameMapper(new DecapitalizeNameMapper());
            x.setAttributesForPrimitives(false);
reader.setXMLIntrospector(x);
reader.registerBeanClass( Customer.class );


The problem lies in the x.setAttributesForPrimitives(true);.  This works
for @id, but not for <name>, or vice versa when set to false when
Customer.java is:

public class Customer{

            private String id;
            private String name;

            .
}

I know I can do the following and make it work, but this is somewhat
bothersome since I have to do this for every entity with an id:
<?xml version="1.0" encoding="UTF-8"?>
<info primitiveTypes="element">
       <element name="customer">
             <attribute name="id" property="id"/>
             <addDefaults/>
       </element>
</info>


How can I get both @id and <name> to be read/written properly
programmatically, exactly as the source file shows?   It would be easier
for me to specify an AttributeDescriptor generically, instead of
providing a betwixt file for all of them.

Am I missing something here?

Thanks,

Kevin Ross

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

Reply via email to