How do I make a group of elements all optional in an XSD (ie. minOccurs="0")?
Asked Answered
G

1

1

Is there an easier way to make a group of elements under a complex tag optional in an XSD? (ie, minOccurs for each should be 0)? Currently, I am adding a minOccurs="0" individually to each element.

Furthermore, is there any way to set/change the default cardinality of minOccurs="1" to minOccurs="0" for all elements that I define in my schema?

Gooden answered 16/4, 2020 at 17:44 Comment(0)
B
1

Furthermore, is there any way to set/change the default cardinality of minOccurs="1" to minOccurs="0" for all elements that I define in my schema?

No, there is not.

Currently, I am adding a minOccurs="0" individually to each element.

This is exactly what you should be doing.

Is there an easier way to make a group of elements under a complex tag optional in an XSD? (ie, minOccurs for each should be 0)?

Yes, but realize that the meaning of the setting is such that it applies to the semantics of the model group. For example, for xs:sequence,

<xs:sequence minOccurs="0">
  <xsl:element name="a"/>
  <xsl:element name="b"/>
  <xsl:element name="c"/>
</xs:sequence>

means that the sequence, collectively, is optional – not that each element is individually optional.

For xs:choice,

<xs:choice minOccurs="0">
  <xsl:element name="a"/>
  <xsl:element name="b"/>
  <xsl:element name="c"/>
</xs:choice>

means that the choice between a, b, and c itself is optional (you may choose zero or one of them) – again, not that each element is individually optional.

Breazeale answered 16/4, 2020 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.