Yamur
Yamur

Reputation: 339

How can add many complexType into the same element type in XSD?

How can I add many compelxType into the same Element type in XSD file? as the example below:

<xs:element name="InboundFlight" type="eInboundFlight"
<xs:complexType name="Flight">
    <xs:sequence>
        <xs:element  name="aircraftIdentification" type="xs:int"/>      
        <xs:element  name="iataFlightDesignator" type="xs:string"/>
    </xs:sequence>     
</xs:complexType>

<xs:complexType name="Aircraft">     
    <xs:sequence>
        <xs:element  name="aircraftRegistration" type="xs:int"/>      
        <xs:element  name="iataAircraftType" type="xs:string"/>
        <xs:element  name="icaoAircraftType" type="xs:string"/>      
    </xs:sequence>     
</xs:complexType> />

Is the code correct? or should add individual elementType for each complexType?

Upvotes: 0

Views: 2109

Answers (1)

kjhughes
kjhughes

Reputation: 111726

You cannot add elements within the start tag of any element in XML, including xs:element in XSD.

To construct a content model for InboundFlight composed of separate flight and aircraft information, use separate elements rather than just separate types for those two parts:

<?xml version="1.0" encoding="utf-8"  ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="InboundFlight" type="eInboundFlight"/>
  <xs:complexType name="eInboundFlight">
    <xs:sequence>
      <xs:element name="Flight">
        <xs:complexType>
          <xs:sequence>
            <xs:element  name="aircraftIdentification" type="xs:int"/>      
            <xs:element  name="iataFlightDesignator" type="xs:string"/>
          </xs:sequence>     
        </xs:complexType>
      </xs:element>
      <xs:element  name="Aircraft">
        <xs:complexType>     
          <xs:sequence>
            <xs:element  name="aircraftRegistration" type="xs:int"/>    
            <xs:element  name="iataAircraftType" type="xs:string"/>
            <xs:element  name="icaoAircraftType" type="xs:string"/>
          </xs:sequence>     
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Recommended reading: XML Schema Part 0: Primer Second Edition

Upvotes: 1

Related Questions