2011-06-29 73 views
8

是否有可能爲complexTypes使用xs:union?

<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> 

那是它應該是什麼樣子。任務是派生一個學生從人,然後使用這兩種類型之一的元素Kunde。

這似乎是無效的。

回答

2

您不能對此使用xs:union。您可以使用xs:choice,也可以將這些元素放入替換組中,這樣它們中的任何一個都可以代替替換組頭部的元素。