Schemas and validity
Complex type
A schema type for elements that have children, attributes, or both — everything a simple type cannot describe.
A complex type carries a content model and an attribute set. It can also have simple content: text like a simple type, plus attributes, which is the shape you need for something like `<price currency="EUR">14.50</price>`.
Complex types can extend or restrict each other, and an element can accept a derived type in an instance document by naming it in xsi:type. That is the mechanism behind most polymorphic XML, and the reason a schema's element list is not always the whole story.
- Defined in
- XSD 1.0 §3.4
- Category
- Schemas and validity
- Also written
- xs:complexType
Shown, not asserted
All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
The shape a complex type with simple content exists to describe.
document.xml <price currency="EUR">14.50</price>What the engine returns
Well-formed.Its text half is still judged by a simple type.
schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="v" type="xs:decimal"/> </xs:schema>value 14.50What the engine returns
Valid asxs:decimal.
What catches people out
- Attributes are declared on the complex type, never on a simple one. That is usually why a schema will not compile.
- Extension adds to a content model; restriction narrows it, and every restricted particle must still be legal in the base.
- xsi:type in an instance document can substitute a derived type at validation time, which schema readers often miss.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- NamespacesXML Schema instanceWhere xsi:type and xsi:schemaLocation come from.
- Schema errorsThe attribute is not allowedWhat happens when an attribute is not in the type's attribute set.
- Datatypesxs:decimalThe type judging the text half of the example above.
Related terms
- Simple typeA schema type whose values are text with no child elements and no attributes — a string, a number, a date, or a restriction of one.
- Content modelThe rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- AttributeA name–value pair on an element's start tag, whose value is always a quoted string.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.