Can we make a element optional or mandatory depending on value of any other element in XSD

后端 未结 1 1948
暗喜
暗喜 2021-01-06 05:37

In XSD i have one element x which takes values (a,b)

There is another element y

Is there any way using XSD so that i can make y as mandatory when value of x

相关标签:
1条回答
  • 2021-01-06 06:30

    Have a look at XML Schema Part 0: Primer Second Edition, section 2.2.1 Occurrence Constraints.

    It says:

    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.

    Because an attribute value cannot be deduced from other schema content in XML Schema, what you want to achieve is impossible (with XML Schema).

    (I don't know if Relax NG can do this, but you may investigate if it supports such content-dependent definitions.)

    0 讨论(0)
提交回复
热议问题