Castor XML Mapping: How to map to different XML fields using the same Java Class

244 Views Asked by At

Is that possible to make a mapping to map to different xml fields using the same Java Class? For example, I have a Person class:

public class Person
{
   private String name;
   private String address;
}

However, I have two xmls for Person, but their "address" in xml has different tag names:

  xml 1:
 <name>xxxx</name>
 <address> xxxxxx </address>

  xml 2:
  <name>xxxx</name>
  <addr> xxxxxx </addr>

So in this case, I can define two Person classes with different "address" fields, but is there a way to use the same mapping for both "address" and "addr"? thanks.

    <class name="Person">   
         <map-to xml="person" />
         <field name="name" type="string">
           <bind-xml name="name" node="element"/>
         </field>
         <field name="address" type="string">
           <bind-xml name="address" node="element"/>  // and also "addr"??
         </field>
0

There are 0 best solutions below