繁体   English   中英

XSD Element Not Null or Empty Constraint when other Element has a specific value

[英]XSD Element Not Null or Empty Constraint when other Element has a specific value

大家好,我正在使用 XSD 1.0 版。 我有两个元素

<Manufacturer/>
<LocationCode/>

我的位置代码 XSD 验证是

<xs:element name="LocationCode" minOccurs="1" nillable="false">
  <xs:simpleType>
     <xs:restriction base="xs:string">
       <xs:minLength value="1"/>
     </xs:restriction>
  </xs:simpleType>
</xs:element>

目前,我的 xsd 验证位置代码不是 null 或为空。 但我只希望此验证在制造商设置为“APPLE”时生效,如此处所示

<Manufacturer>APPLE</Manufacturer>
<LocationCode>232<LocationCode>

如果制造商是其他东西,则位置可以为空

<Manufacturer>Microsoft</Manufacturer>
<LocationCode/>

我搜索了 web,我发现这只能用 xsd 1.1 版来完成。 但是对于我上面给出的 1.0 版示例,肯定有解决方法吗?

“一定有……?” 为什么? 如果不是因为 XSD 1.0 中的限制,XSD 1.1 就不会被发明出来。

这不能在 XSD 1.0 中完成。 如果您无法访问 XSD 1.1 处理器,通常的解决方法是使用 Schematron 添加第二个验证步骤。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM