2013-02-18 10 views
5

動作しない私は、継承しようと要素を制限するが、私は(日食検証中)エラー次取得していますよ:XSD制限が

タイプの粒子が有効ではありませんベースの粒子 の制限。

"Description"要素は "TypeDevice"要素の一部であってはなりません。私はちょうどなぜそれを得ることができません。これは可能であるべきです(このtutorialによる):

私を助けることができる人は誰ですか?タイプTypeDeviceは一つだけであるのに対し

挨拶、

ビル

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com" xmlns="http://www.example.com" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
    <!-- Abstract Base Class --> 
    <xs:complexType name="AbstractDevice" abstract="true"> 
    <xs:sequence> 
     <xs:element name="Name" type="xs:string" /> 
     <xs:element name="Description" type="xs:string" /> 
    </xs:sequence> 
    <xs:attribute name="id" type="xs:string" /> 
    </xs:complexType> 

    <!-- Inheritance with restriction --> 
    <xs:complexType name="TypeDevice"> 
    <xs:complexContent> 
     <xs:restriction base="AbstractDevice">         
     <xs:sequence> 
      <xs:element name="Name" type="xs:string" /> 
     </xs:sequence> 
     <xs:attribute name="id" type="xs:string" use="required" /> 
     </xs:restriction>       
    </xs:complexContent> 
    </xs:complexType> 

    <xs:complexType name="TypeRoot"> 
    <xs:sequence> 
     <xs:element name="Device" type="TypeDevice" /> 
    </xs:sequence>     
    </xs:complexType> 
    <xs:element name="Configuration" type="TypeRoot" /> 
</xs:schema> 

答えて

4

タイプAbstractDeviceは、2つの必須要素を有します。したがって、TypeDeviceは、基本タイプAbstractDeviceの有効なインスタンスではありません。有効にするには、Description要素にminOccurs="0"を追加するか、派生を回して拡張子を使用する必要があります。

+0

あなたの答えをありがとう。しかし、私はこれがまさに要素に適用された制限でできることだと思っていました。リンクされたチュートリアルではこれを正確に行います(派生したelletの "Book"の要素 "Author"を制限で制限しています)私はここで何か誤解しているかもしれません。基本要素の "minOccurs = 0"に設定します。 – Bill