Xml 是否可以对complexTypes使用xs:union?
Xml 是否可以对complexTypes使用xs:union?,xml,xsd,union,Xml,Xsd,Union,它应该是这样的。任务是从Person派生一个Student,然后使其能够为元素Kunde使用两种类型中的一种 这似乎无效。您不能为此使用xs:union。您可以使用xs:choice,也可以将元素放在替换组中,这样它们中的任何一个都可以出现在替换组头部的元素的位置。Hi Michael,是否可以将重复的xs:choice提取到一个可以重用的命名实体中xs:union做到了这一点,它非常有用 <xs:element name="Kunde" type="tKunde"/> <
它应该是这样的。任务是从Person派生一个Student,然后使其能够为元素Kunde使用两种类型中的一种
这似乎无效。您不能为此使用xs:union。您可以使用xs:choice,也可以将元素放在替换组中,这样它们中的任何一个都可以出现在替换组头部的元素的位置。Hi Michael,是否可以将重复的xs:choice提取到一个可以重用的命名实体中
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>