开发者

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

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

There is ano开发者_JS百科ther element y

Is there any way using XSD so that i can make y as mandatory when value of x is b and optional if value of x is a


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜