This document is also available in these non-normative formats: XML, XHTML with changes since version 1.0 marked, XHTML with changes since previous Working Draft marked, Independent copy of the schema for schema documents, Independent copy of the DTD for schema documents, Independent tabulation of components and microcomponents, and List of translations.
Copyright © 2008 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This is a ↑ member-only review version which will in due course become a ↑ Last Call Public Working Draft of W3C XML Schema Definition Language (XSD) 1.1. It ↑has no formal standing within W3C; it↑ is here made available for review by W3C members↓ and the public↓. XSD 1.1 retains all the essential features of XSD 1.0, but adds several new features to support functionality requested by users, fixes many errors in XSD 1.0, and clarifies wording. ↑ This draft was created on 2 September 2008. It reflects (unless otherwise noted elsewhere) all decisions on this document made by the Working Group through 13 June 2008. The document thus incorporates all decisions made by the Working Group to date. ↑
For those primarily interested in the changes since version 1.0, the appendix Changes since version 1.0 (non-normative) (§H) is the recommended starting point. It summarizes both changes made since XSD 1.0 and some changes which were expected (and predicted in earlier drafts of this specification) but have not been made after all. Accompanying versions of this document display in color all changes to normative text since version 1.0 and since the previous Working Draft.
The Last Call review period for this document extends until 12 September 2008. Comments on this document should be made in W3C's public installation of Bugzilla, specifying "XML Schema" as the product. Instructions can be found at http://www.w3.org/XML/2006/01/public-bugzilla. If access to Bugzilla is not feasible, please send your comments to the W3C XML Schema comments mailing list, www-xml-schema-comments@w3.org (archive) Each Bugzilla entry and email message should contain only one comment.
Although feedback based on any aspect of this specification is welcome, there are certain aspects of the design presented herein for which the Working Group is particularly interested in feedback. These are designated "priority feedback" aspects of the design, and identified as such in editorial notes at appropriate points in this draft. Any feature mentioned in a priority feedback note should be considered a "feature at risk": the feature may be retained as is, modified, or dropped, depending on the feedback received from readers, schema authors, schema users, and implementors.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document has been produced by the W3C XML Schema Working Group as part of the W3C XML Activity. The goals of XSD 1.1 are discussed in the document Requirements for XML Schema 1.1. The authors of this document are the members of the XML Schema Working Group. Different parts of this specification have different editors.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
The English version of this specification is the only normative version. Information about translations of this document is available at http://www.w3.org/2003/03/Translations/byTechnology?technology=xmlschema.
The presentation of this document has been augmented to
identify changes from a previous version, controlled by dg-temp.xml. Three kinds of changes are highlighted:
↑new, added text↑,
↑changed text↓, and
↓deleted text↓.
This chapter defines the mechanisms by which this specification establishes the necessary precondition for ·assessment·, namely access to one or more schemas. This chapter also sets out in detail the relationship between schemas and namespaces, as well as mechanisms for modularization of schemas, including provision for incorporating definitions and declarations from one schema in another, possibly with modifications.
Conformance (§2.4) describes three levels of conformance for schema processors, and Schemas and Schema-validity Assessment (§5) provides a formal definition of ·assessment·. This section sets out in detail the 3-layer architecture implied by the three conformance levels. The layers are:
Layer 1 specifies the manner in which a schema composed of schema components can be applied to in the ·assessment· of an instance element information item. Layer 2 specifies the use of <schema> elements in XML documents as the standard XML representation for schema information in a broad range of computer systems and execution environments. To support interoperation over the World Wide Web in particular, layer 3 provides a set of conventions for schema reference on the Web. Additional details on each of the three layers is provided in the sections below.
The sub-sections of Schema Component Details (§3) define an XML representation for type definitions and element declarations and so on, specifying their target namespace and collecting them into schema documents. The two following sections relate to assembling a complete schema for ·assessment· from multiple sources. They should not be understood as a form of text substitution, but rather as providing mechanisms for distributed definition of schema components, with appropriate schema-specific semantics.
<include>)Schema components for a single target namespace can be assembled from several ·schema documents·, that is several <schema> element information items:
include Element Information Item<include
id = ID
schemaLocation = anyURI
{any attributes with non-schema namespace . . .}>
Content: (annotation?)
</include>
A <schema> information item may contain any
number of <include> elements. Their
schemaLocation attributes, consisting of a URI
reference, identify other ·schema documents·, that is <schema> information items.
The ·XSD schema· corresponding to <schema>
contains not only the components corresponding to its definition
and declaration [children], but also all the components of all
the ·XSD schemas· corresponding to any
<include>d schema documents. Such included schema
documents must either (a) have the same
targetNamespace as the <include>ing
schema document, or (b) no targetNamespace at all,
in which case the <include>d schema document is converted to the <include>ing schema document's
targetNamespace.
schemaLocation
[attribute] successfully resolves
one or more of the following is true:application/xml or
text/xml with an XML declaration for
preference, but this is not required), which in turn
corresponds to a <schema> element
information item in a well-formed information set.targetNamespace
[attribute], and its ·actual value· is identical to the
·actual value· of the targetNamespace
[attribute] of D1 (which must have such an
[attribute]).targetNamespace [attribute].targetNamespace [attribute] (but D1
does).targetNamespace
[attribute] whose value is the same as the ·actual value· of the
targetNamespace [attribute] of D1;↓
↓↓↑obtained by performing on D2 the transformation
specified in Transformation for Chameleon Inclusion (§G.1);↑
D2′ corresponds to a conforming schema (call it S2).
targetNamespace [attribute] to D2,
whose value is the same as that of the targetNamespace
[attribute] of D1, and (b) updates all unqualified
QName references so that their namespace names become the
·actual value· of the targetNamespace [attribute].
Implementations need not use the [XSLT 2.0]
stylesheet given in Transformation for Chameleon Inclusion (§G.1),
as long as the same result is produced.targetNamespace
[attribute], but neither B nor
C does, then the effect is as if
A included B' and
B' included C', where
B' and C' are identical to
B and C respectively,
except that they both have a
targetNamespace [attribute] the same as
A's.
schemaLocation [attribute] to fail to resolve
at all,
in which case the corresponding inclusion must not be performed. It
is an error for it to resolve but the rest of clause 1
above to fail to be satisfied. Failure to resolve is likely
to cause less than complete ·assessment· outcomes, of course.<redefine>)Editorial Note: Priority Feedback Request
The Working Group requests feedback from readers, schema authors, implementors, and other users of this specification as to the desirability of retaining, removing, deprecating, or not deprecating the use of <redefine>. Since the <override> facility provides similar functionality but does not require a restriction or extension relation between the new and the old definitions of redefined components, the Working Group is particularly interested in learning whether users of this specification find that requirement useful or not.
In order to provide some support for evolution and versioning, it is possible to incorporate components corresponding to a schema document with modifications. The modifications have a pervasive impact, that is, only the redefined components are used, even when referenced from other incorporated components, whether redefined themselves or not.
redefine Element Information Item<redefine
id = ID
schemaLocation = anyURI
{any attributes with non-schema namespace . . .}>
Content: (annotation | (simpleType | complexType | group | attributeGroup))*
</redefine>
A <schema> information item may contain any number of <redefine> elements. Their schemaLocation attributes, consisting of a URI reference, identify other ·schema documents·, that is <schema> information items.
The ·XSD schema· corresponding
to <schema> contains not only the components corresponding to its definition and declaration [children], but also
all the components of all the ·XSD schemas· corresponding to any <redefine>d schema documents.
Such schema documents must either (a) have the same
targetNamespace as the <redefine>ing schema document, or
(b) no targetNamespace at all, in which case the <redefine>d schema document is converted to the <redefine>ing schema document's targetNamespace.
This mechanism is intended to provide a declarative and modular approach to schema modification, with functionality no different except in scope from what would be achieved by wholesale text copying and redefinition by editing. In particular redefining a type is not guaranteed to be side-effect free: it can have unexpected impacts on other type definitions which are based on the redefined one, even to the extent that some such definitions become ill-formed.
v1.xsd:
<xs:complexType name="personName">
<xs:sequence>
<xs:element name="title" minOccurs="0"/>
<xs:element name="forename" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="addressee" type="personName"/>
v2.xsd:
<xs:redefine schemaLocation="v1.xsd">
<xs:complexType name="personName">
<xs:complexContent>
<xs:extension base="personName">
<xs:sequence>
<xs:element name="generation" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
<xs:element name="author" type="personName"/>
v2.xsd has everything specified
by v1.xsd, with the personName type redefined, as
well as everything it specifies itself. According to
this schema, elements constrained
by the personName type may end with a generation
element. This includes not only the author element, but also the
addressee element.schemaLocation [attribute] must
successfully resolve.schemaLocation
[attribute] successfully resolves
one or more of the following is true:targetNamespace
[attribute], and its ·actual value· is identical to the
·actual value· of the targetNamespace
[attribute] of D1 (which must have such an
[attribute]).targetNamespace [attribute].targetNamespace [attribute] (but D1
does).targetNamespace
[attribute] whose value is the same as the ·actual value· of the
targetNamespace [attribute] of D1;↓
↓↓↑obtained by performing on D2 the transformation
specified in Transformation for Chameleon Inclusion (§G.1);↑
D2′ corresponds to a conforming schema (call it S2).
restriction or extension among its
grand-[children] the ·actual value· of whose base
[attribute] must be the same as the ·actual value· of its own
name attribute plus target namespace;ref [attribute] is the same as the
·actual value· of its own name attribute plus
target namespace
and that <group> does not have an <element>
ancestor, then
all of the following are true:minOccurs and maxOccurs
[attribute] is 1 (or ·absent·).name attribute
plus target namespace successfully ·resolves· to a
model group definition in S2.ref [attribute] is the same as the
·actual value· of its own name attribute plus
target namespace, then it has exactly one such group.name attribute
plus target namespace successfully ·resolves· to an
attribute group definition in S2.name in
the <redefine>d schema document, as defined in Schema Component Details (§3), except that its {name} is ·absent· and its {context} is the redefining component, as defined in clause 1.2 below;ref [attribute] whose ·actual value· is the same as the item's name plus target namespace is
·resolved·, a component which corresponds to the top-level definition item of that name and the appropriate kind in
S2 is used.<override>)The <redefine> construct defined
in Including modified component definitions (<redefine>) (§4.2.3)
is useful in schema evolution and versioning,
when it is desirable to have some guaranteed restriction or extension
relation between the old component and the redefined component.
But there are occasions when the schema author simply wants to
replace old components with new ones without any constraint.
Also, existing XSD processors
have implemented conflicting and non-interoperable interpretations
of <redefine>, and the <redefine>
construct is ·deprecated·.
The <override> construct defined in this section
allows such unconstrained replacement.
override Element Information Item<override
id = ID
schemaLocation = anyURI
{any attributes with non-schema namespace . . .}>
Content: (annotation | (simpleType | complexType | group | attributeGroup | element | attribute | notation))*
</override>
A <schema> information item may contain any number of
<override> elements. Their schemaLocation
attributes, consisting of a URI reference, identify
("point to")
other ·schema documents·,
that is <schema> information items.
The ·XSD schema· corresponding to <schema> contains not
only the components corresponding to its definition and declaration
[children], but also all the components mapped to by the
(possibly modified) source declarations in any
overridden schema documents (after the
modifications described below). Overridden schema documents must
either (a) have the same targetNamespace as the
overriding schema document, or (b) no targetNamespace at all, in
which case the overridden schema document is converted to the overriding schema
document's targetNamespace.
The overriding schema document may override any source declarations for ·named· components which appear among the [children] of the <schema>, <redefine>, or <override> elements in the overridden schema document.
The definitions within the <override> element itself are not required to be similar in any way to the source declarations being overridden. Not all the source declarations of the overridden schema document need be overridden.
As this mechanism is very similar to <redefine>, many similar
kinds of caution need to be taken in using <override>. Please
refer to Including modified component definitions (<redefine>) (§4.2.3) for details.
v1.xsd:
<xs:complexType name="personName">
<xs:sequence>
<xs:element name="firstName"/>
<xs:element name="lastName"/>
</xs:sequence>
</xs:complexType>
<xs:element name="addressee" type="personName"/>
v2.xsd:
<xs:override schemaLocation="v1.xsd">
<xs:complexType name="personName">
<xs:sequence>
<xs:element name="givenName"/>
<xs:element name="surname"/>
</xs:sequence>
</xs:complexType>
</xs:override>
<xs:element name="author" type="personName"/>
v1.xsd has a complex type named
personName children with a sequence of firstName
and lastName. The schema corresponding to v2.xsd
overrides personName, by providing a different sequence of
element children. All elements with the personName type are
now constrained to have the sequence of givenName and
surname. This includes not only the author
element, but also the addressee element.schemaLocation [attribute] must successfully resolve.
schemaLocation [attribute]
successfully resolves one or more of the following is true:targetNamespace [attribute], and its
·actual value· is identical to the ·actual value· of the targetNamespace
[attribute] of D1 (which must have such an [attribute]).
targetNamespace
[attribute].
targetNamespace [attribute] (but D1
does).
xs:override (§G.2)↑. Then
D2′ corresponds to a conforming schema (call it S2).
<include>) (§4.2.2).
xs:override (§G.2)↑. Then
D2′ corresponds to a conforming schema (call it S2).
<include>) (§4.2.2).
xs:override (§G.2)
is to make D2′ identical to D2 except that some elements in
D2 are replaced with those in D1's <override>
(call it O1), as follows.
For each element information item E2 in the [children] of D2's
<schema>, <redefine>, or
<override> information item, the appropriate case among the following is true:name
attribute, then D2′ has an element identical to E1 in E2's
place.<redefine>) (§4.2.3);
import, as defined in
References to schema components across namespaces (<import>) (§4.2.5);
and overriding, as defined in this section,
that if the same schema document is both (a) included, imported, or
redefined, and (b) non-vacuously overridden, or if the same
schema document overridden twice in
different ways, then
the resulting schema will have duplicate and conflicting versions
of some components and will not be conforming,
just as if two different schema documents had been
included, with different declarations for the same
·named· components.
The transformations specified in the following sections in the form of [XSLT 2.0] stylesheets are used when assembling schemas from multiple schema documents. Implementations do not have to perform [XSLT 2.0] transformation, or use the stylesheets given here, as long as the same result is produced.
targetNamespace [attribute] is included
(Assembling a schema for a single target namespace from
multiple schema definition documents
(<include>) (§4.2.2)), redefined
(Including modified component definitions (<redefine>) (§4.2.3)), or overridden
(Overriding component definitions (<override>) (§4.2.4)) by another <schema>
D1 with a targetNamespace [attribute], the following
transformation, specified here as an
[XSLT 2.0] stylesheet, is applied to D2
before its contents are mapped to schema compnents. The
transformation performs two tasks:targetNamespace [attribute] to D2, whose value
is the same as that of the targetNamespace [attribute] of
D1.
targetNamespace [attribute].
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc">
<xsl:param name="newTargetNamespace" as="xs:anyURI"
required="yes"/>
<xsl:param name="prefixForTargetNamespace" as="xs:NCName"
select="f:generateUniquePrefix(0)"/>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="xs:schema">
<xsl:copy>
<xsl:namespace name="{$prefixForTargetNamespace}"
select="$newTargetNamespace"/>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="targetNamespace"
select="$newTargetNamespace"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="attribute(*, xs:QName)
[namespace-uri-from-QName(.)='']">
<xsl:attribute name="{name()}"
select="concat($prefixForTargetNamespace,
':',
local-name-from-QName(.)"/>
</xsl:template>
<xsl:function name="f:generateUniquePrefix" as="xs:NCName">
<xsl:param name="try" as="xs:integer"/>
<xsl:variable name="disallowed"
select="distinct-values(//*/in-scope-prefixes())"/>
<xsl:variable name="candidate"
select="xs:NCName(concat('p', $try))"/>
<xsl:sequence select="if ($candidate = $disallowed) then
f:generateUniquePrefix($try+1)
else
$candidate"/>
</xsl:function>
</xsl:transform>xs:overrideoverrideElement parameter
and (b)
the <schema> element of the schema document D2
identified by the schemaLocation attribute of O1
as the overriddenSchema parameter.
The transformation
produces another <schema> D2′, which is equivalent
to D2 except that some elements in D2 are replaced with those in
D1's <override> (call it O1), as follows.
For each element information item E2 in the [children] of D2's
<schema>, <redefine>, or
<override> information item, the appropriate case among the following is true:
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc">
<xsl:param name="ov" as="schema-element(xs:override)"/>
<xsl:param name="schema" as="schema-element(xs:schema)"/>
<xsl:template match="schema-element(xs:schema)">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="xs:include | xs:import | xs:redefine"/>
<xsl:apply-templates/>
<xsl:copy>
</xsl:template>
<xsl:template match="xs:schema/*">
<xsl:variable name="component" select="."/>
<xsl:variable name="replacement"
select="$ov/xs:replace
[@ref=f:componentName($component)
and
@component=node-name($component)"/>
<xsl:choose>
<xsl:when test="$replacement">
<xsl:copy>
<xsl:attribute name="name" select="local-name()"/>
<xsl:copy-of select="$replacement"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="f:componentName" as="xs:QName">
<xsl:param name="component" as="element()"/>
<xsl:sequence select="QName($component/../@targetNamespace,
$component/@name)"/>
</xsl:function>
</xsl:transform><xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc""
exclude-result-prefixes="f">
<xsl:import-schema
namespace="http://www.w3.org/2001/XMLSchema"
schema-location="../namespace/XMLSchema.xsd"/>
<xsl:param name="overrideElement" as="schema-element(xs:override)"/>
<xsl:param name="overriddenSchema" as="schema-element(xs:schema)"/>
<xsl:template name="start">
<xsl:apply-templates select="$overriddenSchema"/>
</xsl:template>
<xsl:template match="schema-element(xs:schema) | xs:redefine">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:include | xs:import" priority="5">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="xs:schema/*
| xs:redefine/*
| xs:override/*"
priority="3">
<xsl:variable name="original" select="."/>
<xsl:variable name="replacement"
select="$overrideElement/*
[node-name(.)=node-name($original)
and
f:componentName(.)=f:componentName($original)]"/>
<xsl:copy-of select="($replacement, $original)[1]"/>
</xsl:template>
<xsl:function name="f:componentName" as="xs:QName">
<xsl:param name="component" as="element()"/>
<xsl:sequence select="
QName($component/ancestor::xs:schema/@targetNamespace,
$component/@name)"/>
</xsl:function>
</xsl:transform>