Shital,

I am not 100% sure if that is possible to achieve with Castor(to map these 2 XML elements having only that class with only 3 fields, somebody please prove that i'm wrong :))), however here is another solution that should work good enough
(assuming that you are willing to change the Address class a little bit):


......................................................................................................
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd";>
<mapping>
<class name="com.acme.model.AddressBook">
<map-to xml="inputXML"/>
<field name="currentAddress" type="com.acme.model.Address">
<bind-xml name="CurrentAddress"/>
</field>
<field name="previousAddress" type="com.acme.model.Address">
<bind-xml name="PreviousAddress"/>
</field>
</class>


   <class name="com.acme.model.Address">
       <field name="currentStreet" type="string">
          <bind-xml name="CurrentStreet" node="element"/>
       </field>
       <field name="currentState" type="string">
          <bind-xml name="CurrentState" node="element"/>
       </field>
       <field name="currentCity" type="string">
          <bind-xml name="CurrentCity" node="element"/>
       </field>
       <field name="previousStreet" type="string">
          <bind-xml name="PreviousStreet" node="element"/>
       </field>
       <field name="previousState" type="string">
          <bind-xml name="PreviousState" node="element"/>
       </field>
       <field name="previousCity" type="string">
          <bind-xml name="PreviousCity" node="element"/>
       </field>
   </class>
</mapping>
.....................................................................................................
Hope this helps,
Best regards,
Dragos

Shital Tushar Agarkar wrote:

Thanks Dragos.

But this does not solve my problem as here u r using different classes.
My problem is I want to use same address class for Current Address and
PreviousAddress element. And I want to bind same Address class to
CurrrentAddress and Previous Address class.

I'll explain it here,

I have a class Address {
        String street;
        String state;
        String city;
}

Now while writing mapping file, I want to use same Address class for
CurrentAddress and PreviousAddress elements.

Can anyone help me in this?

Regards,
Shital

-----Original Message-----
From: Dragos Haiduc [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 22, 2004 6:39 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-user] Mapping file problem



I'll dare to have a shot at it, see below the mapping code:
.......................................................................
...............
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd";>
<mapping>
<class name="com.acme.model.Address">
<map-to xml="inputXML"/>
<field name="" type="com.acme.model.CurrentAddress">
<bind-xml name="CurrentAddress"/>
</field>
<field name="" type="com.acme.model.PreviousAddress">
<bind-xml name="PreviousAddress"/>
</field>
</class>


   <class name="com.acme.model.CurrentAddress">
       <field name="currentStreet" type="string">
          <bind-xml name="CurrentStreet" node="element"/>
       </field>
       <field name="currentState" type="string">
          <bind-xml name="CurrentState" node="element"/>
       </field>
       <field name="currentCity" type="string">
          <bind-xml name="CurrentCity" node="element"/>
       </field>
   </class>

   <class name="com.acme.model.PreviousAddress">
       <field name="previousStreet" type="string">
          <bind-xml name="PreviousStreet" node="element"/>
       </field>
       <field name="previousState" type="string">
          <bind-xml name="PreviousState" node="element"/>
       </field>
       <field name="previousCity" type="string">
          <bind-xml name="PreviousCity" node="element"/>
       </field>
   </class>
</mapping>
.......................................................................
.......................
Shital Tushar Agarkar wrote:



Hi,

I am new to Castor and does not know much about it. I want to use castor for marshelling and unmarshelling also.



My problem is: I have to use same class to represent two different elements in a xml file. Can anyone please help me in this?



I am elaborating my problem.



Sample outputXML:



<inputXML>

<CurrentAddress>

           <CurrentStreet>street1</CurrentStreet>

           <CurrerntState>State1</CurrentState>

           <CurrentCity>city1</CurrentCity>

</CurrentAddress>

<PreviousAddress>

           <PreviousStreet>street1</PreviousStreet>

           <PreviousState>State1</PreviousState>

           <PreviousCity>city1</PreviousCity>

</PreviousAddress>

</inputXML>





For this purpose I want to use Address class, to represent both the address elements. But I am not getting how to write mapping file for the same.



Guys, please help me in this .



Thanks in advance

-Shital



-----------------------------------------------------------------------


-


----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user








----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user




------------------------------------------------------------------------

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user





----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user

Reply via email to