XSD Simple Types vs Complex Types

Estimated study time: 14 minutes.

XSD splits every type into one of two categories: simple types, which hold only text with no child elements or attributes, and complex types, which can contain child elements, attributes, or both.

Simple Types

<xs:element name="duration" type="xs:string"/>
<xs:element name="seats" type="xs:integer"/>

Built-in simple types include xs:string, xs:integer, xs:decimal, xs:date, and xs:boolean. You can also define your own restricted simple type:

<xs:simpleType name="courseLevel">
  <xs:restriction base="xs:string">
    <xs:enumeration value="beginner"/>
    <xs:enumeration value="intermediate"/>
    <xs:enumeration value="advanced"/>
  </xs:restriction>
</xs:simpleType>

Complex Types

<xs:complexType name="courseType">
  <xs:sequence>
    <xs:element name="title" type="xs:string"/>
    <xs:element name="duration" type="xs:string"/>
  </xs:sequence>
  <xs:attribute name="id" type="xs:string"/>
</xs:complexType>

Complex types describe elements that have structure — nested child elements and/or attributes — rather than just a plain value.

Quick Rule of Thumb

  • If an element only ever holds plain text and nothing else, it's a simple type.
  • If an element has children or attributes, it must be a complex type.
💡 Tip: Define reusable custom simple types (like an enumerated courseLevel) once, then reference them across multiple elements to keep your schema consistent.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with the Data Analytics Course at Uncodemy.

Explore XML Course →