XML technologies / XML Schema / Creating extensible schemas / Need for open schemas
(Excerpt from “XML Schema” by Eric van der Vlist)
Reusable, flexible schema components are desirable, but mainly benefit schema creation and maintenance rather than documents. Although application designers often tightly associate instances with their original schemas and applications, documents commonly outlive both. Documents or fragments are reused in other contexts or hold added information, yielding combinations their authors never imagined.
Opening vocabularies to support controlled evolution goes beyond open-schema design. It changes how documents are viewed and applications written, including tolerance for unexpected elements and attributes. Grammar-based schemas such as W3C XML Schema have a fundamental problem: everything not explicitly permitted is forbidden, making them closed by default.
Define openness as changing the original content model without a new schema, unlike schema modification discussed in Extensible schemas. Available tools are type substitution through xsi:type and wildcards.
xsi:type
This openness is allowed by default. Applications using complex-type extension, simple-type union or components without attributes block or blockDefault may be surprised by type substitution in instances.
Beyond unexpected openness, explicitly extending element-defining complex types for substitution through attribute xsi:type provides a first controlled approach. Applications can process attribute xsi:type to identify the extension they encounter.
Wildcards
Namespaces and wildcards are the strongest tools for openness. Many vocabularies, including W3C XML Schema, allow attributes with a different namespace from the target on every element, while tightly controlling unqualified attributes and their own namespace’s attributes. Values of attribute processContents, lax, skip and strict, adjust the desired openness. skip is completely open, strict requires schemas for encountered namespaces, and lax is intermediate.
Foreign elements are often more intrusive than attributes and can be confined to containers. W3C XML Schema uses this for its own vocabulary, allowing arbitrary elements within documentation. Other vocabularies, such as RELAX NG or RSS 1.0, simply accept elements from any namespace except their target.
This flexibly accepts unexpected information, but is limited with several defined namespaces: no special value means any namespace except those defined in the consolidated schema.
What about substitution groups?
Mentioning xsi:type raises substitution groups too: yes, they offer alternative content models, but no, they work only if predefined in the schema. xsi:type can work without schema preparation. Despite similarities, substitution groups belong more to flexible than open schemas.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de