我想通過元素名稱來驗證父元素是否具有唯一的子元素。 我還需要驗證是否存在至少一個可能的元素。XML架構唯一子元素
例
<StorageTypes>
<Status/>
<Warning/>
<Error/>
</StorageTypes>
將是有效的,但
<StorageTypes>
<Status/>
<Status/>
<Warning/>
<Error/>
</StorageTypes>
和
<StorageTypes>
</StorageTypes>
將是無效的。
我已經嘗試過使用xs:unique,選擇當前節點,但無法一般地選擇帶有字段元素的元素。
以下是我期待做的事情,但它不是我尋找的強大解決方案。我希望能夠添加更多的類型,而不必爲每次更改都更改xpath。
<element ect.>
<xs:unique name="something">
<xs:selector xpath="."/>
<xs:field xpath="Status"/>
<xs:field xpath="Warning"/>
<xs:field xpath="Error"/>
</xs:unique>
</element>
這可能嗎?這是好的做法嗎?任何意見,將不勝感激。
謝謝,我會更進的取代基。我有一個類似的解決方案,你提供的,但使用枚舉。我們一直在尋找更多的東西通用的,將允許延期的未來架構,而無需改變框架架構。 – gettingSmarter