Open Content vs Wildcards in XML Schema 1.1
XML Schema (XSD) 1.1 provides flexible validation mechanisms through traditional wildcards and the newer open content feature. While both mechanisms allow documents to contain undeclared or variable elements and attributes for extensibility, they differ fundamentally in their scope, declaration levels, and structural placement within complex types. Understanding these differences enables schema designers to build robust, forward-compatible data models without unnecessarily complex content definitions.
What Are Wildcards?
Wildcards in XML Schema are represented by the
<xs:any> and <xs:anyAttribute>
particles. They allow any well-formed XML element or attribute from
specified namespaces to appear in an instance document.
- Positional Placement: An
<xs:any>wildcard is treated as a distinct particle within a specific model group (<xs:sequence>,<xs:choice>, or<xs:all>). Its position relative to other declared elements is strictly fixed. - Granular Control: You explicitly define the exact point in the document structure where an unexpected element can appear.
- Process Contents: Wildcards use
processContents(strict,lax, orskip) to dictate whether the validator must find an associated schema definition for the matched content.
What Is Open Content?
Open content (<xs:openContent>) is an XSD 1.1
feature designed to declare that a complex type can contain unexpected
elements anywhere in its content model, without manually inserting
<xs:any> particles between every declared
element.
- Non-Positional or Suffix Placement: Open content
uses a
modeattribute, which can be set tointerleaveorsuffix. Ininterleavemode, unexpected elements matching the open content’s wildcard definition can appear anywhere among the declared elements. Insuffixmode, undeclared elements must appear after the declared content. - Type-Level Definition: It is specified as a child
of
<xs:complexType>, modifying the entire type’s validation behavior rather than being bound to a single slot inside a sequence or choice. - Global Application: XSD 1.1 introduces
<xs:defaultOpenContent>, which can be defined at the root<xs:schema>level to automatically apply open content rules to all complex types within the schema.
Key Differences
| Feature | Wildcards
(<xs:any>) |
Open Content
(<xs:openContent>) |
|---|---|---|
| Specification Version | XSD 1.0 and XSD 1.1 | XSD 1.1 only |
| Structural Position | Fixed position within a sequence, choice, or all group. | Interleaved anywhere among elements or appended as a suffix. |
| Scope of Declaration | Particle-level (within individual model groups). | Complex type-level or schema-wide (via
<xs:defaultOpenContent>). |
| Modeling Purpose | Explicit extension points at predetermined locations. | Broad extensibility across an entire type or schema without altering individual element structures. |
| Complexity in Large Schemas | High maintenance;
<xs:any> must be manually placed at every extension
point. |
Low maintenance; can be globally applied with a single declaration. |
Summary of Usage
Use wildcards when you need strict control over the exact position where external or dynamic XML content must reside in relation to known elements. Use open content when you want forward compatibility that allows consumers or producers to inject unanticipated elements anywhere within complex types without violating validation constraints.