【发布时间】:2016-02-24 01:26:02
【问题描述】:
我想知道是否可以使用带有可选字段的 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".
我需要minOccurs="0" 和 keyref 约束,如果该字段不存在,则根本不希望执行任何检查(对于 NULL FOREIGN KEYs)。
编辑:在本例中忽略命名空间,我对所有内容都使用了默认命名空间...
【问题讨论】: