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

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念