Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

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.50

    What the engine returns

    Valid as xs: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.

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.