2016-12-03 116 views
1

正如我一直認爲的,xs:restriction用於限制某個simpleType或complexType,因此名稱restriction。但下面的xsd代碼片段是正確的。看看Norwegian_customercountry用complexType覆蓋,所以它被擴展,不受限制。它被重命名。 xs:restriction想要提供什麼?是xs:restriction的超集xs:extension?該片段在WebStorm中進行了驗證。爲什麼這個complexType定義正確

<xs:complexType name="customer"> 
    <xs:sequence> 
     <xs:element name="firstname" type="xs:string"/> 
     <xs:element name="lastname" type="xs:string"/> 
     <xs:element name="country" type="xs:string"/> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="Norwegian_customer"> 
    <xs:complexContent> 
     <xs:restriction base="customer"> 
     <xs:sequence> 
      <xs:element name="firstname" type="xs:string"/> 
      <xs:element name="lastname" type="xs:string"/> 
      <xs:element name="country1"> 
      <xs:complexType> 
       <xs:sequence> 
       <xs:element name="firstname" type="xs:string"/> 
       <xs:element name="lastname" type="xs:string"/> 
       <xs:element name="country" type="xs:string"/> 
       </xs:sequence> 
      </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
     </xs:restriction> 
    </xs:complexContent> 
    </xs:complexType> 

回答

2

但XSD片斷下面是正確的。

不,您的XSD代碼片段不正確Norwegian_customer不是customer的有效限制,因爲它不允許country,只有country1。限制基類型的內容模型的所有部分必須在派生類型中明確允許。

該片段在WebStorm中進行了驗證。

如果Webstorm驗證了這個XSD,那麼它是不符合的。

W3C XML Schema Part 1: Structures Second Edition,具體如下:

注意如下的Xerces基於驗證會告訴你:

[錯誤] try.xsd:13:45:rcase-Recurse.2:粒子之間沒有完整的功能映射。

[錯誤] try.xsd:13:45:derivation-ok-restriction.5.4.2:類型爲 'Norwegian_customer'的錯誤。該類型的粒子不是限制基質粒子的有效限制。

相關問題