milkwood1
milkwood1

Reputation: 394

XSD difference between complexContent and sequence

What's the difference between a sequence and a complexContent in XSD?

I'm very new to XSD, but I've read some articles and the w3schools tutorial on XSD.
I've searched a lot in the internet as well, but nowhere was the difference between the two explained.

An example would be this:

<xs:element name="foo">
    <xs:complexType> 
        <xs:sequence>
            <xs:element name="bar" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

vs

<xs:element name="foo">
    <xs:complexType> 
        <xs:complexContent>
            <xs:element name="bar" type="xs:string" />
        </xs:complexContent>
    </xs:complexType>
</xs:element>

Upvotes: 2

Views: 2971

Answers (1)

kjhughes
kjhughes

Reputation: 111621

While both xs:complexContent and xs:sequence can appear as child elements of xs:complexType, they serve completely different purposes:

  • Use xs:complexContent (with a xs:restriction or xs:extension child element) to define a type that restricts or extends another type.
  • Use xs:sequence to indicate a sequential ordering of subordinate elements (or other subordinate grouping constructs).

Note that your example of xs:complexContent is invalid as xs:element cannot be a direct child of xs:complexContent.

See also:

Upvotes: 4

Related Questions