微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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是否可以这样做,但你可以调查它是否支持这种依赖于内容的定义.)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。