簡體   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