xml – 我们可以根据XSD中任何其他元素的值使元素成为可选元素或强制元素

前端之家收集整理的这篇文章主要介绍了xml – 我们可以根据XSD中任何其他元素的值使元素成为可选元素或强制元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在XSD中我有一个元素x取值(a,b)

还有另一个要素y

有没有办法使用XSD,这样我可以在x的值为b时将y设为必需,如果x的值为a,则可选

解决方法

看看 XML Schema Part 0: Primer Second Edition,第 2.2.1 Occurrence Constraints节.

它说:

In general,an element is required to appear when the value of minOccurs is 1 or more. The maximum number of times an element may appear is determined by the value of a maxOccurs attribute in its declaration. This value may be a positive integer such as 41,or the term unbounded to indicate there is no maximum number of occurrences. The default value for both the minOccurs and the maxOccurs attributes is 1.

由于无法从XML Schema中的其他模式内容推断出属性值,因此您无法实现(使用XML Schema).

(我不知道Relax NG是否可以这样做,但你可以调查它是否支持这种依赖于内容的定义.)

猜你在找的XML相关文章