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

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.

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.