2011-12-03 48 views
2

直觀地說,「延伸」是指添加了一些基本類型,不修改基本類型。以下XSDXML架構擴展的語義

<complexType name="B"> 
    <attribute name="A1" type="int" use="required" /> 
    <anyAttribute namespace="##other" processContents="strict" /> 
</complexType> 
<complexType name="D"> 
    <complexContent > 
     <extension base="tns:B"> 
      <!--???--> 
      <attribute name="A1" type="int" use="optional" /> 
      <anyAttribute namespace="##other" processContents="lax" /> 
     </extension> 
    </complexContent> 
</complexType> 

不應編譯。但是XML Schema編譯器(System.Xml.Schema.XmlSchema)不會拋出錯誤。這種反直覺設計的理性是什麼?

+0

我知道其中的原因:XML模式是「結構類型」,而不是「名義打字」 ...... –

回答

0

沒有與該模式的一個問題:

  • 在d,您要添加的屬性A1第二次。

在擴展清單的東西把它添加到定義。在這種情況下,「A1」已經在那裏。任何擴展實例都需要是基礎的有效實例。如果A1不存在,它不會成爲該基地的有效成員。

它看起來像你需要,如果你想使它可選限制B型。