2017-06-29 13 views
0

代替グループをそのグループ内の単一の要素に限定する必要があるようです。ただし、検証中に置換グループや要素を処理するため、直感は特定のカーディナリティにのみ適用されます。たとえば、次のスキーマが有効ではありませんXSD:置換グループの制限

<xs:element name="representedOrganization" type="Organization"/> 
<xs:element name="scopingOrganization" type="Organization" substitutionGroup="representedOrganization"/> 

<xs:complexType name="Test.Parent"> 
    <xs:sequence> 
     <xs:element ref="representedOrganization" minOccurs="0" maxOccurs="1"/> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="Test.Child"> 
    <xs:complexContent> 
     <xs:restriction base="Test.Parent"> 
      <xs:sequence> 
       <xs:element name="scopingOrganization" type="Organization" minOccurs="0" maxOccurs="1"/> 
      </xs:sequence> 
     </xs:restriction> 
    </xs:complexContent> 
</xs:complexType> 

しかし、制限のカーディナリティに小さな変化(すなわちminOccurs)が有効です。

<xs:element name="representedOrganization" type="Organization"/> 
<xs:element name="scopingOrganization" type="Organization" substitutionGroup="representedOrganization"/> 

<xs:complexType name="Test.Parent"> 
    <xs:sequence> 
     <xs:element ref="representedOrganization" minOccurs="0" maxOccurs="1"/> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="Test.Child"> 
    <xs:complexContent> 
     <xs:restriction base="Test.Parent"> 
      <xs:sequence> 
       <xs:element name="scopingOrganization" type="Organization" minOccurs="1" maxOccurs="1"/> 
      </xs:sequence> 
     </xs:restriction> 
    </xs:complexContent> 
</xs:complexType> 

これは動作しません。直感的に...しかし、なぜですか?

答えて

0

これは、2つの場所での処理の間の悪質な相互作用です。 Schema Component Constraint: Particle Valid (Restriction)

  1. は、仕様が明確にその:

    2.1トップレベル要素宣言粒子(RまたはB)1種以上の他の要素宣言との{置換基所属}であります・置換グループ・少なくとも1つの要素宣言を含むものは、{min発生}と{max発生}がパーティクルであり、{particles}が{minで1つのパーティクルで構成される選択グループであるかのように扱われますが発生した場合、その置換グループの各宣言に対して{max}が1となる。 Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup)

  2. 、仕様はそれを明確に:に対応するグループ粒子(全て、選択またはシーケンス)種々の群の粒子の・有効制限される要素宣言粒子について

    ・を{1}の{min occur}と{max}が発生し、{particle}が単一のパーティクルで構成されているBは、パーティクルの派生によって定義されたグループの有効な制限でなければなりません。 、Sequence:Sequence - Recurse)(§3.9.6)、Particle Derivation OK(選択肢:Choice - RecurseLax)(§3.9.6)またはParticle Derivation OK(すべて:All、Sequence:Sequence - Recurse) 3.9.6)、グループがすべてであるかどうか、選択肢またはシーケンス。

これは歪んだ状況を作成し、無効なスキーマが(上記)は、以下に変換される:

<xs:complexType name="Test.Parent"> 
    <xs:sequence> 
     <xs:choice minOccurs="0" maxOccurs="1"> 
      <xs:element name="representedOrganization" type="Organization.Organization" minOccurs="1" maxOccurs="1"/> 
      <xs:element name="scopingOrganization" type="Organization.Organization" minOccurs="1" maxOccurs="1"/> 
     </xs:choice> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="Test.Child"> 
    <xs:complexContent> 
     <xs:restriction base="Test.Parent"> 
      <xs:sequence> 
       <xs:choice minOccurs="1" maxOccurs="1"> 
        <xs:element name="scopingOrganization" type="Organization.Organization" minOccurs="0" maxOccurs="1"/> 
       </xs:choice> 
      </xs:sequence> 
     </xs:restriction> 
    </xs:complexContent> 
</xs:complexType> 

このスキーマはParticle Derivation OK (Choice:Choice -- RecurseLax)に選択レベルのカーディナリティチェックを通過します。ただし、制限されたアイテムの基数がベースタイプの一致するパーティクルのカーディナリティよりも大きいため、(ネストされた)パーティクルのテストは失敗します。

注:パーサーがParticle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup)の問題としてこれを報告する場合があります。これは、要素を選択肢として扱い、ネストされた選択テストを実行するための指示を含むセクションです。例えば、XMLSpyのレポート:

rcase-RecurseAsIfGroup:<要素名= "scopingOrganization" のminOccurs = "0" >が<素子REF = "representedOrganization" のminOccurs = "0モデル群の粒子の有効な制限ではありません">。

派生スキーマを制御できれば、要素を選択肢にラップし、カーディナリティーをこのレベルに移動することで、この問題を克服することができます。