Global versus local XML Schema design is a choice about visibility, identity and reuse. A declaration at the top level of xs:schema enters a namespace-wide symbol space. A declaration inside a complex type belongs to that content model. Neither is inherently superior: the decision depends on whether a concept is a stable part of the vocabulary’s public contract.
Global and local declaration scope
A global element can appear as a document element and can be referenced with ref. A local element is defined where it is used. Global complex and simple types have names and can be assigned to multiple elements. Inline types are anonymous and remain coupled to their containing declaration.
<!-- Global reusable type and global root element -->
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="city" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="order" type="OrderType"/> Here, AddressType is global and reusable. The city element is local to that type. A local declaration can still be namespace-qualified in instance documents; declaration scope and namespace qualification should not be conflated.
Four recurring XSD design patterns
Russian Doll
Russian Doll is useful for a small vocabulary with one obvious document root and little need to reuse inner structures. Navigation is straightforward because the whole model is nested below the root. The limitation appears when another message needs the same inner concept: an anonymous type cannot be referenced elsewhere.
Salami Slice
Salami Slice turns elements into reusable components. Content models refer to global elements rather than declaring local ones. This supports consistent element identity and can be useful with substitution groups, but the schema becomes less self-contained and changes to a shared element have a wider impact.
Venetian Blind
Venetian Blind is a practical default for many business vocabularies. Stable structures become named types, while their child elements stay close to the content model. Only legitimate document roots need global element declarations. This separates structural reuse from element identity.
Garden of Eden
Garden of Eden exposes both types and elements for reuse. It is appropriate when multiple documents, extension schemas or integration partners genuinely depend on those declarations. The governance cost is higher because a large number of names become part of the published contract.
How to choose declaration scope
Start from consumer behavior rather than a pattern label. Make a declaration global when another schema or independent content model needs to refer to it by QName. Use a named type when multiple elements share stable structure. Keep one-off wrapper elements local. Avoid speculative global declarations because every public name adds versioning obligations.
| Question | Likely design move |
|---|---|
| Must this element be a document root? | Declare it globally. |
| Must other schemas reference the element itself? | Use a global element. |
| Do several elements share the same structure? | Create a global named type. |
| Is the structure used only once? | Consider a local declaration or anonymous type. |
| Will consumers extend the type? | Publish a named type with a versioning policy. |
Namespaces and form defaults
A global declaration belongs to the target namespace. For local elements, elementFormDefault="qualified" makes instance elements namespace-qualified unless a declaration overrides the setting. With unqualified, local elements normally carry no namespace even though their containing global element does.
Qualified local elements often make vocabulary identity clearer, particularly when compound documents combine multiple namespaces. Unqualified locals can make instances visually shorter but require consumers to understand the context-dependent namespace boundary.
Analyze the declaration profile
The XSD Design Pattern Analyzer counts global elements, named types, local declarations, anonymous types and references. The result is a heuristic because real schema sets can intentionally mix styles. Use it to identify the dominant structure, then review whether each global name represents a stable public concept.
Frequently asked questions
01What is a global element in XML Schema?
A global element is declared as a direct child of xs:schema. It belongs to the schema target namespace and can serve as a document root or be reused through an element reference.
02What is a local element in XSD?
A local element is declared inside a complex type or model group. Its use is tied to that content model, and its namespace qualification follows form or elementFormDefault settings.
03What is the Russian Doll XSD pattern?
Russian Doll design exposes a global document element and nests anonymous types and local element declarations beneath it. The vocabulary is encapsulated but its inner structures are difficult to reuse independently.
04What is the Salami Slice pattern?
Salami Slice design declares many elements globally and assembles content models with element references. Elements are reusable, although the namespace-wide public surface and coupling are larger.
05What is the Venetian Blind pattern?
Venetian Blind design defines reusable named types globally while keeping most element declarations local. A limited set of global elements acts as document roots.
06What is the Garden of Eden pattern?
Garden of Eden makes both elements and types broadly global. It maximizes reuse and extension points but also exposes a large set of declarations that must be governed carefully.
07Are global XSD declarations always better for reuse?
They are more accessible for reuse, but reuse also creates dependencies. A declaration should be global when it represents a stable public concept, not merely because it might be reused one day.
08Can local elements be namespace-qualified?
Yes. Set elementFormDefault to qualified at schema level or form to qualified on the individual declaration. Scope and namespace qualification are separate concerns.
09Do named types have to be global?
In XSD, a type with a name is declared globally. Types declared inline within an element are anonymous and cannot be referenced by QName from elsewhere.
10Can a schema combine multiple design patterns?
Yes. Production vocabularies frequently use global named types for stable concepts, a few global root elements and local anonymous structures for one-off details.