Patricia,

please have a look at the documentation for the <xsi:type> attribute at
http://castor.org/xml-mapping.html#5.-xsi:type and the use of the
<auto-derive> element in particular.

Werner

Patricia Hartnett wrote:
> Hello,
> 
>  
> 
> I’m trying to unmarshall an input XML file which contains a
> MessageHolder class. This class has a single class variable Object
> object.  Basically the MessageHolder can contain an Object of any type.
> So the XML input file could have a MessageHolder containing a simple
> String or something very complex like CustomerOrders.
> 
>  
> 
> <?xml version="1.0"?>
> 
> <mapping>
> 
>             <class name=" Root">
> 
>                         <map-to xml="data"/>
> 
>                         <field name="Id" type="java.lang.Integer">
> 
>                                     <bind-xml name="cmdId" node="element"/>
> 
>                         </field>
> 
>                         <field name="msgHolder" type="MessageHolder">
> 
>                                     <bind-xml name="get" />
> 
>                         </field>
> 
>             </class>
> 
>  
> 
>             <class name= "Get">
> 
>                         <field name="object">
> 
>                                     <bind-xml name="test" />
> 
>                         </field>
> 
>             </class>
> 
>  
> 
>             <class name=”CustomerDetails”>
> 
>                         <field name=”billingAddress” type =”
> BillingAddress” >
> 
>                                     <bind-xml name="billAddr"/>
> 
>                         </field>
> 
>                         <field name=”shippingAddress” type =”
> ShippingAddress” collection="set">
> 
>                                     <bind-xml name="shipAddr"/>
> 
>                         </field>
> 
>             </class>
> 
>  
> 
>             <class name=”CustomerOrders”>
> 
>                         <field name=”currentOrders” type
> =”CurrentOrders” collection="set">
> 
>                                     <bind-xml name="currOrders"/>
> 
>                         </field>
> 
>             </class>          
> 
> </mapping>
> 
>  
> 
> I tried to use the method suggested in
> http://www.codecomments.com/archive413-2006-1-749262.html
> 
>  
> 
> But the problem is that when I try to unmarshall the data stored in the
> XML file, the object stored in the MessageHolder object is returned as
> an instance of AnyNode.
> 
>  
> 
> ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
> 
> Root root = (Root) unmar.unmarshal(new
> InputSource(bis));                      
> 
> MessageHolder messageHolder = (MessageHolder)root.getMessageHolder;
> 
> AnyNode actionObject = (AnyNode)messageHolder.getObject();
> 
>  
> 
> I would like to unmarshall the object as an instance of the actual class
> it belongs to eg CustomerOrders or CustomerDetails.
> 
> Is there any way to do this ?
> 
>  
> 
> Thanks for reading my question.
> 
>  
> 
> Best Regards,
> 
> Trish.
> 
>  
> 
> Patricia Hartnett
> 
> Software Engineer
> Aircraft Management Technologies
> phone: +353 1 806 1000
> 
> fax : +353 1 806 1025
> e-mail: [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> web: www.flightman.com <http://www.flightman.com/>
> 
> THE INFORMATION IN THIS E-MAIL IS CONFIDENTIAL AND MAY BE LEGALLY
> PRIVILEGED.  IT IS INTENDED SOLELY FOR THE ADDRESSEE.  ACCESS TO THIS
> E-MAIL BY ANYONE ELSE IS UNAUTHORISED.  IF YOU ARE NOT THE INTENDED
> RECIPIENT, ANY DISCLOSURE, COPYRIGHT, DISTRIBUTION OR ANY ACTION TAKEN
> OR OMITTED TO BE TAKEN IN RELIANCE ON IT, IS PROHIBITED AND MAY BE UNLAWFUL.
> 
>  
> 


-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to