user40950
user40950

Reputation: 13

Why use <xsd:sequence> for a single <xsd:element>?

<xsd:complexType>
<xsd:sequence>
<xsd:element name="allowFieldTruncation" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>

In the above example, I have only one element (called allowFieldTruncation) defined under the complex type, and I have no requirement for minOccurs or maxOccurs. Now my question is why should I include a sequence tag – can't the definition be like below?

<xsd:complexType>
<xsd:element name="allowFieldTruncation" type="xsd:boolean"/>
</xsd:complexType>

Upvotes: 1

Views: 571

Answers (1)

kjhughes
kjhughes

Reputation: 111621

Because the XSD spec says so:

<complexType
  abstract = boolean : false
  block = (#all | List of (extension | restriction))
  final = (#all | List of (extension | restriction))
  id = ID
  mixed = boolean : false
  name = NCName
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, 
            (simpleContent | complexContent 
            | ((group | all | choice | sequence)?, 
               ((attribute | attributeGroup)*, anyAttribute?))))
</complexType>

Think of xsd:sequence as one of several model groups required if you wish to specify an xsd:element in a content model. (You could use another besides xsd:sequence.) The design might have allowed no model groups to be specified for "groups" of one element, however as far as exceptions and irregularities go, XSD's squiggly, blurry line had to be drawn somewhere.

Upvotes: 1

Related Questions