Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to use xs:union for complexTypes?

Tags:

xml

union

xsd

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

like image 447
kmindi Avatar asked Jun 29 '11 11:06

kmindi


People also ask

What is XS extension?

Specifies the name of a built-in data type, a simpleType element, or a complexType element. any attributes. Optional. Specifies any other attributes with non-schema namespace.

What is simple type and complexType in XSD?

xs:simpleType define a value type, this value can then be used within an element or attribute (so you could define an double with 2 decimal places or a string in the format of an IP address). xs:complexTypes describe the structure of an element. It can define its textual value, its attributes and its child elements.

What is a global element in XML?

<xs:element name="name" type="xs:string"/> <xs:element name="navn" substitutionGroup="name"/> <xs:complexType name="custinfo"> <xs:sequence> <xs:element ref="name"/>

What is Union in XSD?

<xs:restriction base="xs:positiveInteger"> <xs:maxInclusive value="42"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="sizebystring">


1 Answers

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.

like image 83
Michael Kay Avatar answered Oct 05 '22 17:10

Michael Kay