2017-03-15 40 views
0

如何將許多compelxType添加到XSD文件中的相同元素類型?如下例所示:如何將許多complexType添加到XSD中的相同元素類型?

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

代碼是否正確?或者應該爲每個complexType添加單獨的elementType?

回答

1

您不能在XML中的任何元素的開始標籤內添加元素,包括XSD中的xs:element

構建內容模型InboundFlight單獨飛行和飛機的信息,使用單獨的元素,而不僅僅是單獨的類型爲那些兩個部分組成:

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

推薦閱讀:XML Schema Part 0: Primer Second Edition

相關問題