I am assuming you also have a declaration for the Programmer element,
which doesn't appear in the Schema fragment you posted, something like:

<xsd:element name="Programmer" type="Programmer"
substitutionGroup="Person"/>

(without this element declaration, the instance you show is invalid).

If you do, then you still need to tell XMLBeans to use that element, by
calling XmlObject.substitute(). See the thread "xsi:type related
question (long)":
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200804.mbox/brows
er

Radu

> -----Original Message-----
> From: Henry Barnett [mailto:[EMAIL PROTECTED] 
> Sent: Monday, May 05, 2008 1:19 PM
> To: [email protected]
> Subject: element with ref problem
> 
> Hi,
> I have the following xsd
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>             xmlns="urn:test" 
>             targetNamespace="urn:test">
>       <xsd:element name="smallCar" type="Car"/>
>       <xsd:complexType name="Car">
>           <xsd:all>
>               <xsd:element ref="person" minOccurs="1" maxOccurs="1" />
>           </xsd:all>
>       </xsd:complexType>
> 
>   <xsd:element name="person" type="Person" abstract="true"/>
>   
>   <xsd:complexType name="Person" abstract="true">
>     <xsd:attribute name="id" type="xsd:ID" />
>   </xsd:complexType>
>   
>   <xsd:complexType name="Programmer">
>     <xsd:complexContent>
>       <xsd:extension base="Person">
>         <xsd:attribute name="pId" type="xsd:int" />
>       </xsd:extension>
>     </xsd:complexContent>
>   </xsd:complexType>
> </xsd:schema>
> 
> Which generates all the right classes, I then have the following test.
> 
> import org.apache.xmlbeans.XmlOptions;
> 
> import test.Car;
> import test.Programmer;
> import test.SmallCarDocument;
> 
> public class Helper {
>       public static void main(String args[]) {
>               SmallCarDocument doc =
> SmallCarDocument.Factory.newInstance();
>               Car car = doc.addNewSmallCar();
>               
>               Programmer person = Programmer.Factory.newInstance();
>               person.setPId(22);
>               person.setId("ID");
>               car.setPerson(person);
>               
>               XmlOptions xmlOptions = new XmlOptions();
>               xmlOptions.setSavePrettyPrint();
>               xmlOptions.setSavePrettyPrintIndent(4);
>               
>               String output = doc.xmlText(xmlOptions);
>               System.out.println(output);
>       }
> }
> 
> Which outputs
> <urn:smallCar xmlns:urn="urn:test">
>     <urn:person pId="22" id="ID" xsi:type="urn:Programmer"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
> </urn:smallCar>
> 
> Where I would have expected it to output <urn:smallCar 
> xmlns:urn="urn:test">
>     <Programmer pId="22" id="ID"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
> </urn:smallCar>
> 
> The former of the two being invalid because person is abstract
> >> error: cvc-elt.2: Element '[EMAIL PROTECTED]:test' is abstract 
> and cannot be
> used in an instance
> I've searched and looked for an answer to make it so that 
> XMLBeans will serialize it into the latter to no avail. Can 
> anyone help?
> 
> Regards,
> Henry
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

Notice:  This email message, together with any attachments, may contain 
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated 
entities,  that may be confidential,  proprietary,  copyrighted  and/or legally 
privileged, and is intended solely for the use of the individual or entity 
named in this message. If you are not the intended recipient, and have received 
this message in error, please immediately return this by email and then delete 
it.

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

Reply via email to