Schemas and validity
Content model
The rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
Every schema language has one, spelled differently. XSD builds them from sequence, choice and all, with minOccurs and maxOccurs for cardinality; DTDs use a regular-expression-like syntax; RELAX NG uses patterns. The vocabulary differs, the question does not.
Two failure messages come from content models more than anything else: an element that is not expected here, and a missing one that was. Both name the element the validator was looking at, which is often not the element you need to change.
- Defined in
- XSD 1.0 §3.8
- Category
- Schemas and validity
- Also written
- element model, particle
Shown, not asserted
This claim is 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.
Content models are a validation concept: a document in the wrong order is still well-formed.
document.xml <note><body>text</body><to>Ada</to></note>What the engine returns
Well-formed.
What catches people out
- Order matters in an xs:sequence and not in xs:all, and xs:all has restrictions on cardinality that catch people converting between them.
- maxOccurs="unbounded" is the usual intent for a repeating record. The default is 1, and omitting it silently caps the document at one.
- A model permitting mixed content cannot also constrain where the text goes.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Schema errorsThis element is not expectedThe message when a child appears where the model does not allow it.
- Schema errorsMissing child element(s)The message when the model wanted more than the document supplied.
- ToolsXSD validatorWhere you will meet both messages.
Related terms
- ElementThe unit of structure in XML: a start tag, its content, and a matching end tag — or a single self-closing tag when there is no content.
- ValidA well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.
- Complex typeA schema type for elements that have children, attributes, or both — everything a simple type cannot describe.
- Mixed contentAn element containing both text and child elements, interleaved — the model prose uses and data rarely does.
- DTDThe original XML schema language: element and attribute declarations written in their own non-XML syntax, plus the entity declarations nothing else provides.
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.