Hi Arnaud,

I tried it before without the 'name' attribute (forgot to remove it in the
message) and it also did not work.
So I prepared a small sample for testing:

-----------------------------------------------
public class ElementA {}
-----------------------------------------------
public class ElementB extends ElementA {}
-----------------------------------------------
import java.util.Vector;
public class List
{
    private Vector elements = null;
    public List() {elements = new Vector();}
    public Vector getElements() {return elements;}
    public void setElements(Vector newElements) {elements = newElements;}
    public void addElement(ElementA element) {elements.addElement(element);}
}
-----------------------------------------------
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.mapping.Mapping;
import java.io.FileWriter;

public class Writer
{
    public static void main(String[] args) throws Throwable
    {
        List list = new List();
        list.addElement(new ElementA());
        list.addElement(new ElementB());
        
        FileWriter fw = new FileWriter("out.xml");
        Marshaller marshaller = new Marshaller(fw);
        Mapping mapping = new Mapping();
        mapping.loadMapping("mapping.xml");
        marshaller.setMapping(mapping);
        marshaller.marshal(list);
        fw.close();
    }
 }
-----------------------------------------------
<mapping>
        <class name="List">
                <map-to xml="List"/>
                <field name="elements" type="ElementA" collection="vector">
                        <!--bind-xml name="elements" node="element"/-->
                        <bind-xml autonaming="deriveByClass"
node="element"/>
                </field>
        </class>
        <class name="ElementA">
                <map-to xml="ElementA"/>
        </class>
        <class name="ElementB" extends="ElementA">
                <map-to xml="ElementB"/>
        </class>
</mapping>
-----------------------------------------------
This produces the following output:
-----------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<List>
    <elements/>
    <elements xsi:type="ElementB"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</List>
-----------------------------------------------

I cannot find any mistake in this code. What I'm doing wrong?

Thank you very much.

Matthias


-----Original Message-----
From: Arnaud Blandin [mailto:blandin@;intalio.com]
Sent: Mittwoch, 6. November 2002 15:20
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] [xml] xsi:type handling in 0.9.3.9 and 0.9.4


Hi Mathias,

Auto-naming won't work if you specify 'name' at the same time, just
remove your name attribute from the <bind-xml/> element.

Arnaud

> -----Original Message-----
> From: Matthias Peschel [mailto:M.Peschel@;intershop.de]
> Sent: Wednesday, November 06, 2002 1:48 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] [xml] xsi:type handling in 0.9.3.9 and
> 0.9.4
> 
> Hi Arnaud,
> 
> it seems that I left out an important thing:
> I have an ElementList class that contains a list of
> PersistentElement
> objects. The PersistentElement is the base class for a lot of other
> classes.
> So the only place where I could add a bind-xml mapping is the field
> declaration "elements". But this doesn't work like you described.
> 
> here are my mappings:
> 
>       <class name="ElementList">
>               <map-to xml="ElementList"/>
>               <field name="elements" type="PersistentElement"
> collection="vector">
>                       <bind-xml name="PersistentElement"
node="element"
> autonaming="deriveByClass"/>
>               </field>
>       </class>
>       <class name="PersistentElement">
>               <map-to xml="PersistentElement"/>
>       </class>
>       <class name="ComponentReference" extends="PersistentElement">
>               <map-to xml="ComponentReference"/>
>               ... some fields ...
>       </class>
>       ... other classes that derive from PersistentElement ...
> 
> What I'm doing wrong?
> 
> Thx
> Matthias
> 
> -----Original Message-----
> From: Arnaud Blandin [mailto:blandin@;intalio.com]
> Sent: Mittwoch, 6. November 2002 12:44
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] [xml] xsi:type handling in 0.9.3.9 and
> 0.9.4
> 
> 
> Hi Mathias,
> 
> If you are using a Mapping you can add the following in the
> definition
> of the ComponentReference element:
> <bind-xml autonaming="deriveByClass"/>
> That should do the trick...
> For more information on the <bind-xml> element, please take a look
> at
> http://www.castor.org/xml-mapping.html#3.5-The-<bind-xml>-element
> 
> Hope that helps,
> 
> Arnaud
> 
> 
> 
> -----Original Message-----
> From: Matthias Peschel [mailto:M.Peschel@;intershop.de]
> Sent: Wednesday, November 06, 2002 12:28 PM
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] [xml] xsi:type handling in 0.9.3.9 and 0.9.4
> 
> Hi,
> 
> Until now we used Castor 0.9.3.9 and now we want to upgrade to
> 0.9.4.
> In the old version the marshalled xml looked like this:
> 
> ��� <ComponentReference id="abc"/>
> 
> In the 0.9.4 version it looks different:
> 
> ��� <PersistentElement id="abc" xsi:type="ComponentReference"/>
> 
> ComponentReference is�a concrete class that extends the abstract
> class
> PersistentElement.
> I know, that the xsi:type attribute specifies the concrete sub class
> of
> the element. But in 0.9.3.9 the attribute�was only generated when
> using
> interfaces and not when using abstract classes. But
> PersistentElement is
> an abstract class. So it worked in 0.9.3.9.
> 
> Did you extend the usage of ysi:type also for abstract classes?
> Is there a way to get the same results as in 0.9.3.9?
> 
> Many thanks.
> 
> Matthias
> 
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>       unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>       unsubscribe castor-dev

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

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

Reply via email to