Carson Pun
Carson Pun

Reputation: 1792

In XSD, is it possible to define the value of maxOccurs by a variable?

For example, I have the following XSD line:

<xs:element name="child_name" type="xs:string" maxOccurs="10"/>

The child_name tag is maxed to have 10 instances. Is it possible to have that 10 referred as some sort of variable and then defined it elsewhere? (The following code not legit, but just showing if possible to have something like some_variable, and then have some_variable defined elsewhere?)

<xs:element name="child_name" type="xs:string" maxOccurs="some_variable"/>

Upvotes: 2

Views: 1430

Answers (1)

kjhughes
kjhughes

Reputation: 111571

No, element/@maxOccurs may only be a nonNegativeInteger or unbounded.

There are no provisions for allowing it to be a variable, nor are there provisions for declaring or setting variables.

These probably aren't the sort of XSD-level support you're seeking, but here are a couple work-around alternatives:

  1. Use an entity reference at the XML level as a sort of variable.
  2. Compose/rewrite the XSD dynamically such as via XSLT to vary the value of element/@maxOccurs.

Upvotes: 2

Related Questions