オプションのフィールドで keyref 要素を使用することは可能でしょうか。
たとえば、次のスキーマが与えられた場合:
<element name="myElement" type="myType">
<complexType>
<sequence>
<element name="subElem">
<complexType>
<attribute name="name" type="string"/>
<attribute name="type" type="string"/>
</complexType>
</element>
<element name="subElem2">
<complexType>
<sequence>
<element name="subSubElem" minOccurs="0">
<complexType>
<attribute name="type" type="string"/>
</complexType>
</element>
</sequence>
<attribute name="name" type="string" use="required"/>
</complexType>
</element>
</sequence>
</complexType>
<key name="uniqueSubElem">
<selector xpath="subElem"/>
<field xpath="@name"/>
<field xpath="@type"/>
</key>
<keyref name="uniqueSubElemRef" refer="uniqueSubElem">
<selector xpath="subElem2"/>
<field xpath="@name"/>
<field xpath="subSubElem/@type"/>
</keyref>
</element>
この例では、XML で subSubElem を指定しないと、バリデーターが文句を言います。
Not enough values specified for <keyref name="uniqueSubElem"> identity constraint specified for element "myElement".
と keyref 制約の両方が必要minOccurs="0"
です。フィールドが存在しない場合は、チェックを実行したくないだけです (NULL FOREIGN KEY の場合)。
編集:この例では名前空間を無視します。すべてにデフォルトの名前空間を使用しました...