kmindi
kmindi

Reputation: 4834

is it possible to use xs:union for complexTypes?

<xs:element name="Kunde" type="tKunde"/>


<xs:complexType name="tKunde">
    <xs:union memberTypes="tPerson tStudent"></xs:union>
</xs:complexType>
<xs:complexType name="tPerson">
    <xs:sequence>
        <xs:element name="Vorname" type="xs:string"/>
        <xs:element name="Nachname" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="tStudent">
    <xs:complexContent>
        <xs:extension base="tPerson">
        <xs:sequence>
            <xs:element name="Matrikelnummer" type="xs:int" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

Thats what it should look like. The task is to derive a Student from Person and then make it possible to use one of the two types for the element Kunde.

This seems to be invalid.

Upvotes: 10

Views: 5962

Answers (1)

Michael Kay
Michael Kay

Reputation: 163342

You can't use xs:union for this. You can either use xs:choice, or put the elements in a substitution group so any of them can appear in place of the element at the head of the substitution group.

Upvotes: 6

Related Questions