我想知道是否可以将 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".
我需要 theminOccurs="0"
和 keyref 约束,如果该字段不存在,则根本不希望执行任何检查(对于 NULL FOREIGN KEYs)。
编辑:忽略此示例的名称空间,我对所有内容都使用了默认名称空间...