Shevach
Shevach

Reputation: 737

How to make sure an element does not exist in XSD?

Can I use maxOccurs="0"?

Example:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string" maxOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Do you have a better way for this?

Upvotes: 1

Views: 408

Answers (1)

kjhughes
kjhughes

Reputation: 111726

Well, as long as minOccurs="0", you could set maxOccurs="0", but more commonly, you'd simply omit the element altogether to prevent it from appearing:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Upvotes: 2

Related Questions