W3C XML Schema Working Group"> XML Schema: Structures"> XML Schemas: Datatypes"> ]>
XML Schema Part 1: Structures &XSP1.version; &WD-XSP1;-&iso.doc.date; W3C Working Draft &draft.day; &draft.month; &draft.year; The following SHOULD be in the publoc, but the DTD doesn't currently allow it: the stylesheet fakes it.

(in XML (with its own DTD, XSL stylesheet (July XSL WD version) and IE5 stylesheet (XSL as supported by version 5 of Microsoft's Internet Explorer)) and HTML, with separate provision of the schema and DTD for schemas described herein.

&XSP1.base;/&WD-XSP1;/ http://www.w3.org/TR/xmlschema-1/ http://www.w3.org/1999/05/06-xmlschema-1/ Henry S. Thompson University of Edinburgh ht@cogsci.ed.ac.uk David Beech Oracle dbeech@us.oracle.com Murray Maloney Commerce One murray@muzmo.com Noah Mendelsohn Lotus noah_mendelsohn@lotus.com

This is a W3C Working Draft for review by members of the W3C and other interested parties in the general public.

It has been reviewed by the XML Schema Working Group and the Working Group has agreed to its publication. Note that not that all sections of the draft represent the current consensus of the WG. Different sections of the specification may well command different levels of consensus in the WG. Public comments on this draft will be instrumental in the WG's deliberations.

Please review and send comments to www-xml-schema-comments@w3.org (archive).

This draft incorporates a substantial change to the concrete syntax from the previous public working draft, intended to simplify it and make it easier to use (the full text of the proposal from the working group's task force , along with a cover note containing a discussion of alternatives considered and outstanding issues , are available as background).

Three major components of this document are marked below as out-of-date and/or under construction: major efforts by task forces from within the WG are underway with respect to these, and their reports are linked from this draft. We felt it was important to present this work to the public, in keeping with our obligation to produce drafts for public inspection and comment on a regular basis, despite the "Under Construction" signs posted below. It is our intention henceforth to publish interim working drafts with greater frequency, both to keep interested parties informed of our progress, and to emphasize the "work in progress" nature of these drafts.

Sections which are not the status quo, that is on which the working group has not yet reached consensus, are marked with an asterisk (*) at the end of the section title. But please note that all the facilities described herein are in a preliminary state of design. The Working Group anticipates substantial changes, both in the mechanisms described herein, and in additional functions yet to be described. The present version should not be implemented except as a check on the design and to allow experimentation with alternative designs. The Schema WG will not allow early implementation to constrain its ability to make changes to this specification prior to final release.

A list of current W3C working drafts can be found at http://www.w3.org/TR. They may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress".

XML Schema: Structures is part 1 of a two-part draft of the specification for the XML Schema definition language. This document proposes facilities for describing the structure and constraining the contents of XML 1.0 documents. The schema language, which is itself represented in XML 1.0, provides a superset of the capabilities found in XML 1.0 document type definitions (DTDs).

Boston, Mountain View, Toronto, et al.: World-Wide Web Consortium, XML Working Group, 1999.

Created in electronic form using XML.

English Extended Backus-Naur Form (formal grammar) Extensible Markup Language (XML) 1999-09-02: HST: Marked non-status-quo sections as such. 1999-09-01: HST: incorporated Section 2 examples from 'Simple', modified to include some attributes. Massaged explanatory text. 1999-08-22: HST: incorporated 'Simple' section 3 changes and started to smooth over the joints. 1999-07-18: DB: updated definition of "Schema" following WG and IG email discussion. Changed "Schemata" to "Schemas" except where directly quoted from Requirements doc. Clarified in 2.5 that elements and attributes have separate symbol spaces (public comment). Fixed assorted typos. 1999-06-23: HST: pushed & down to lowest level, fixed incoherent validity definition in 6.2.3.7 to agree with the note which follows. Wrapped validation text from 3.4 in appropriately named div4's. 1999-06-20: HST: stripped out validation 1999-05-03: MCM: Updated schema and DTD. Package and test. 1999-05-03 Integration of final editors' concerns for WD1. Includes HT work on constraints. 1999-05-02 NRM General cleanup of first few chapters. Remove chapter 4 redundancy (tuple discussion) with new validity rules. 1999-05-02: HST: still chipping away at validity. Redefined the XSDL/XDTL entities. 19940502: MCM: mostly annotating the schema. Also moved info about abstract grammar into Chapter 2. Chapter 3 now starts right into defining a schema. Edited text entities to make them easier to manage. 19940501: HST: various 1999-04-30: NRM : revisions to chapter 4 1999-04-28: DB (pp HST) : promised edits for improved consistency and definition of 'schema'; suggested modifications to 3.4.9/10 and 3.5 1999-04-39: HST : integrated DB's edits, completely rewrote 6.1, replaced virtually all <B> with correct <...ref> 1999-04-28: DB (pp HST) : promised edits for improved consistency and definition of 'schema'; suggested modifications to 3.4.9/10 and 3.5 1999-04-23: HST : Got all productions sorted using 'nt' and correct IDs. 1999-04-21 : HST : Added lots of IDs and constraint heads: Validates w/o error 1999-04-21 : HST : Converted with no content changes to speak of from MCM-XSDL-19990416.html. This version has only ID/IDREF related errors left.
Introduction

This document sets out the structural part (&XSP1;) of the XML Schema definition language.

Chapter 2 presents a for &XSP1;, including an introduction to schema constraints, types, schema composition, and symbol spaces. The abstract and concrete syntax of &XSP1; are introduced, along with other terminology used throughout the specification.

Chapter 3 reconstructs the core functionality of XML 1.0, plus a number of extensions, in line with our stated requirements . This chapter discusses the declaration and use of datatypes, archetypes, element, content models, attributes, attribute groups, model groups, refinement, entities and notations.

Chapter 4 presents , including the validation of namespace qualified instance documents, import, inclusion and export of declarations and definitions, schema paths, access to schemas, and related rules for schema-based validity.

Chapter 5 is a placeholder for , which will eventually provide a standardized means for including documentation in the definition of a schema.

Chapter 6 discusses , including the rules by which instance documents are validated, and responsibilities of schema-aware processors.

The normative addenda include a and a , which is an XML Schema schema for &XSP1;, a [not yet written] and . Non-normative appendixes include a and .

Documentation Conventions

This Working Draft document was produced using an DTD and an stylesheet.

The following highlighting is used to present technical material in this document:

A term is something we use a lot.

Sample Abstract Syntax Production left right1 right2

A non-normative example illustrating use of the schema language, or a related instance.

<schema name='http://www.muzmo.com/XMLSchema/1.0/mySchema' >

And an explanation of the example.

The following highlighting is used for non-normative commentary in this document:

A recorded issue.

Notes shared among the editorial team.

General comments directed to all readers.

Purpose

The purpose of &XSP1; is to provide an inventory of XML markup constructs with which to write schemas.

The purpose of an &XSP1; schema is to define and describe a class of XML documents by using these constructs to constrain and document the meaning, usage and relationships of their constituent parts: datatypes, elements and their content, attributes and their values, entities and their contents and notations. Schema constructs may also provide for the specification of additional information such as default values. Schemas are intended to document their own meaning, usage, and function through a common documentation vocabulary. Thus, &XSP1; can be used to define, describe and catalogue XML vocabularies for classes of XML documents.

Any application that consumes well-formed XML can use the &XSP1; formalism to express syntactic, structural and value constraints applicable to its document instances. The &XSP1; formalism will allow a useful level of constraint checking to be described and validated for a wide spectrum of XML applications. However, the language defined by this specification does not attempt to provide all the facilities that might be needed by any application. Some applications may require constraint capabilities not expressible in this language, and so may need to perform their own additional validations.

Relationship To Other Work

The definition of &XSP1; is a part of the W3C XML Activity. It is in various ways related to other ongoing parts of that Activity and other W3C WGs

&XSP1; has a dependency on the data typing mechanisms defined in its companion , published simultaneously with this recommendation.

&XSP1; has not yet identified requirements or dependencies.

&XSP1; has a requirement to support modularization of HTML.

See http://www.w3.org/XML/Group/1999/03/xml-schema-i18n-notes

&XSP1; has not yet documented requirements or dependencies.

Need to reference Cambridge Communique as soon as it's published.

&XSP1; has a requirement to support accessibility.

&XSP1; has significant dependencies on .

&XSP1; defines its own Information Set Contributions.

&XSP1; will have requirements for subsequent Information Set Working Drafts.

&XSP1; has not yet identified requirements or dependencies.

&XSP1; must interoperate with XML 1.0 and subsequent revisions.

&XSP1; has a requirement to support dimensions and aggregate datatypes.

Terminology

The terminology used to describe &XSP1; is defined in the body of this specification. The terms defined in the following list are used in building those definitions and in describing the actions of &XSP1; processors:

Conforming documents and processors are permitted to but need not behave as described.

Conforming documents and processors are required to behave as described; otherwise they are in error.

A violation of the rules of this specification; results are undefined. Conforming software may detect and report an error and may recover from it.

An error which a conforming processor must detect and report to the application.

(Of strings or names:) Two strings or names being compared must be character for character the same.

(Of URIs or schemaNames:) identical, according to the rules for identity in .

Conceptual Framework

This specification uses a number of terms that are common to many of the fields of endeavor that have influenced the development of XML Schema. Unfortunately, it is often the case that these terms do not have the same definitions in all of those fields. This section attempts to provide definitions of terms as they are used to describe the conceptual framework, and the remainder of the specification.

Kinds of XML Documents

Since XML schemas are themselves specified as XML documents or elements within documents, it is useful to clarify the relationships between certain kinds of XML documents and elements:

An XML element information item which conforms to some schema. See for a discussion of information items: in brief, an element information item is the component of an infoset which corresponds to an element. From it other information items are accessible, including attributes, namespace declaration and content. See and for the means by which an instance identifies the schema(s) to which it conforms. Note we will often speak loosely about an (XML) instance document, but this is just shorthand for element information item associated with the document element of an XML document. Similarly, we will often speak of elements when we mean element information item.

An XML element information item which, along with its descendants, satisfies all the Constraints on Schemas in this specification. An XML Schema establishes a set of rules for constraining the structure and articulating the information set of XML document instances.

Note that it is possible to specify a schema to which schemas themselves must conform, and this is given in . An XML 1.0 DTD to which schemas must conform is also provided in .

Any schema is ipso facto an element information item. It follows that the rules specified herein for validity apply to all of the following kinds of XML element information items:

Elements that are not schemas;

Schemas applicable to documents that are not schemas;

The schema applicable to schemas.

Likewise, rules for schemas in general apply to the particular schema for schemas, which is an instance conforming to itself.

On schemas, constraints and contributions

The specification describes two kinds of constraints on XML documents: well-formedness and validity constraints. Informally, the well-formedness constraints are those imposed by the definition of XML itself (such as the rules for the use of the < and > characters and the rules for proper nesting of elements), while validity constraints are the further constraints on document structure provided by a particular DTD.

Three kinds of normative statements about the impact of &XSP1; components on instances are distinguished in this specification:

Constraints on the form and content of schemas themselves, above and beyond those expressed in ;

Constraints on the form and content of instances, which the instances must satisfy to be schema-valid;

Augmentations to instance information sets which follow as a consequence of schema-validation.

Schema Information Set Contributions are not as new as might at first appear: XML 1.0 validation augments the XML 1.0 information set in similar ways, e.g. by providing values for attributes not present in instances, and by implicitly exploiting type information for normalization or access, e.g. consider the effect of NMTOKENS on attribute whitespace, and the semantics of ID and IDREF. By including Schema Information Set Contributions, we are trying to make explicit something XML 1.0 left implicit.

&XSP1; not only reconstructs the DTD constraints of XML 1.0 using XML instance syntax, it also adds the ability to define new kinds of constraints. For example, although the author of an XML 1.0 DTD may declare an element type as containing character data, elements, or mixed content, there is no mechanism with which to constrain the contents of elements to only character data of a particular form, such as only integers in a specified range.

This specification supports the expression of just such constraints by including in the mechanism for the declaration of elements the option of specifying that its contents must consist of a valid string expression of a particular datatype. A number of other mechanisms are added which improve the expressive power, usability and maintainability of schemas as a means to defining the structure of XML documents.

Schemas, Types and Elements

The purpose of a schema is to identify a set of components for use in XML documents and to provide the rules for their correct combination.

The schema language is itself a set of elements and attributes. We will describe these, and show how they are used. But first, a quick example of an XML document.

Alice Smith 123 Maple Street Mill Valley CA 90952 1999-05-25 Get these things to me in a hurry, my lawn is going wild! Lawnmower, model BUZZ-1 1 148.95 Please confirm this is the electric model Baby Monitor, model SNOOZE-2 1 39.98 ]]>

The purchase order consists of a main element with several subordinate elements. Most of the subelements have simple atomic types such as string or date, drawn from the repertoire of built-in datatypes defined in , but some are complex. We use the archetype element when declaring elements which allow elements in their content and/or may carry attributes. For example, we can define an archetype called Address as follows:

]]>

The consequence of this definition is that an element whose type is declared to be Address must consist of five elements and may have one attribute. Though each has a distinct name, four of the elements and the attribute will simply contain a string in a document instance while one will contain a number.

If we're going to use the same element in a number of places, we can declare it once and refer to it by name elsewhere:

]]>

This declaration restricts the comment element to text content and no attributes.

We can define a PurchaseOrderType for our PurchaseOrder element, referring to the definitions of Address and comment as above, as:

]]>

The shipDate element daughter of PurchaseOrderType is declared above as having an atomic type, as in the Address example above. The comment daughter is declared by reference to a global element declaration. Similarly, the shipTo and Items daughters are declared as having complex types which must be defined elsewhere in the current schema. The comment daughter and the orderDate attribute are optional, the others are obligatory.

Further integration of the concrete syntax for type definitions is desireable, e.g. by using 'type' for both archetypes and and datatypes, but the details of a consistent and clear way to do this have not yet been agreed.

Since an element declaration's type can identify either a datatype or an archetype, and there are separate symbol spaces for these two, the possibility of ambiguity arises. This is resolved in favour of the archetype, e.g. even if a datatype called Address existed (either builtin or user-defined), the above declaration for shipTo would refer to the user-defined archetype of that name.

The separation of the datatype and archetype name symbol spaces is primarily motivated by the decision to allow unqualified reference to the ab initio and built-in datatypes. Should this decision be reversed, as was suggested in the report of the simplification Task Force, then the unification of the two symbol spaces could proceed with minimal negative impact. The potential for error which arises from unexpected shadowing of an old datatype by a new archetype would be removed.

A definition creates a new archetype or datatype; a declaration enables the appearance in a document instance of an element or attribute with a specific name and type. In the schema, we see both the definition of several types, and also several elements and attributes declared as usages of these types. For example, Address is defined to be an archetype, while within the definition of Address we see five declarations of elements and one attribute declaration. These declarations are not themselves types, but rather an association between a name and constraints which govern the appearance of that name in documents governed by the containing schema.

In the case of attribute declarations, the constraints are on the allowed value, always by reference to a datatype:

]]>

In the case of element declarations, the constraints are on the allowed content and attributes, by reference to an archetype or a datatype (in which case no attributes are allowed):

]]>

Because Address is defined in the schema to have certain elements as its content and to allow a certain attribute, any shipTo element appearing in an instance must include those elements and may have that attribute, while any comment element may not have any attributes, but any text content.

As well as naming a datatype or archetype in an attribute or element declaration, we can embed the type definition immediately within the element declaration:

0 ]]>

Here not only is the archetype of the Item element given in line, but also the datatype referenced by its quantity daughter (the built-in integer datatype) is also qualified inline by adding a subrange constraint.

Taken together the examples above constitute a complete schema for the initial PurchaseOrder example instance. They are drawn together in a single complete schema in .

Schemas and their component parts

The next chapter sets out the &XSP1; approach to schemas and formal definitions of their component parts. Here we informally summarize the key constructs used in defining schemas. A 'Yes' in the 'Name apears in instances?' column indicates that the name will appear in instances -- other names are for schema use only.

&XSP1; Feature Purpose Named? Name appears in instances?
A wrapper element containing all the definitions and declarations comprising a schema. Yes No
An atomic type (content constraint), such as 'integer', that applies to character data in an instance document, whether it appears as an attribute value or the contents of an element. The mechanisms for defining datatypes are set out elsewhere, in &XSP2;. Yes No
A complete set of constraints for elements in instance documents, applying to both contents and attributes. Yes No
An association between a name for an element and a type. An element declaration for 'A' is comparable to a DTD declaration <!ELEMENT A .....>. Yes (local or global) Yes
An association between a name for an attribute and a datatype, together with occurrence constraints such as 'required' or 'default'. The association is local to its surrounding archetype. Yes (local) Yes
Content type Either a datatype or a content model. A content type applies to the contents of elements in an instance document (but not their attribute values). It provides a unifying abstraction for the constraints which apply to the contents of elements, but introduces no additional features. No No
A constraint that applies to the contents of elements in an instance document. Content models do not include attribute declarations. No No
Components for constructing content models which allow only element content. Includes facilities for grouping and sequencing, as well as for declaration of and reference to elements. No (but see below) No
An association between a name and a reusable collection of attribute declarations. Yes No
Model groups are part of the content model building block abstraction, but are unnamed and cannot be referenced for reuse. A named model group is an association between a name and a model group, allowing for reuse. Yes No
One archetype may be defined as refining one or more other archetypes, acquiring content type and/or attributes therefrom. Yes No
Extends the current schema with definitions and/or declarations from elsewhere, retaining the association with their origin. No No
Integrates definitions and/or declarations from elsewhere into the schema being defined, as if they had been defined locally. No No
Names and Symbol Spaces

As indicated in the third column of the tables above, most of the components listed have names, which provide for references within the schema, and sometimes from one schema to another. For example, an attribute declaration can refer to a named datatype, such as 'integer'. A content model can refer to an element, and so on.

If all such names were assigned from the same 'pool', then it would be impossible to have e.g. a datatype named 'integer' and an element with the name 'integer' in the same schema. Accordingly we introduce the idea of a symbol space (avoiding 'name space' to avoid confusion with 'Namespaces in XML' ).

There is a single distinct symbol space within a given schema for each of the abstractions named above other than 'Attribute' and 'element': within a given symbol space, names are unique, but the same name may appear in more than one symbol space without conflict. In particular note that the same name can refer to both a type and an element, without conflict or necessary relation between the two.

Attributes and local element declarations are special, in that every archetype defines its own attribute symbol space and local element symbol space, which are distinct from each other. In addition, top-level elements (whose declarations are not contained within an archetype definition) reside in their own symbol space.

Abstract and Concrete Syntax

&XSP1; is presented here primarily in the form of an abstract syntax, which provides a formal specification of the information provided for each declaration and definition in the schema language. The abstract syntax is presented using a simplified BNF. Defined terms are to the left. Their components are to the right, with a small amount of meta-syntax: ()s for grouping, | to separate alternatives, ? for optionality, * and + for iteration. Terms in italics are primitives, not expanded here, either because they are defined elsewhere (e.g. URI, defined by ) or because they can only be grounded once a concrete syntax is decided on (e.g. choice).

An abstract syntax production prefixed with a number in brackets (e.g. [3]) is normative; other abstract syntax is either for purposes of explanation, or is a duplicate (for convenience) of a normative definition to be found elsewhere.

The abstract syntax illustrates the expressive power of the language, and the relationships among its component parts. The abstract syntax can be used to evaluate the expressive power of &XSP1;, but not its look and feel. In particular, please note that neither ordering within or between productions or choice of names is significant, and that any particular concrete syntax is not constrained by these.

The concrete syntax of &XSP1;, the exact element and attribute names used in a schema, are a key feature of its proposed design. The concrete syntax is the form in which the schema language is used by schema authors. Though its elements and attributes are often different from the terms of the abstract syntax BNF, the features and expressive power of the two are congruent. The concrete syntax profoundly affects the convenience and usability of the schema language.

We include a preliminary concrete syntax in this draft, via examples, paradigms and in and . Unlike the previous version, in which the intention was to stay quite close to the abstract syntax, in this version we have begun to take convenience and clarity into account.

Schema Definitions and Declarations

The principal purpose of &XSP1; is to provide a means for defining schemas that constrain the contents of instances and augment the information sets thereof.

The Schema

A schema contains some preamble information and a set of definitions and declarations.

Schema top level schema preamble dds* dds datatypeDefn | archetypeDefn | elementDecl | attrGroupDefn | modelGroupDefn | notationDecl | entityDecl preamble xmlSchemaRef targetNamespace schemaVersion model export? import? include? xmlSchemaRef URI targetNamespace URI schemaVersion string-value model open | refinable | closed

preamble consists of an xmlSchemaRef specifying the URI for &XSP1;; the targetNamespace specifying the URI of the namespace which this schema is about; and a schemaVersion specification for private version documentation purposes and version management.

See for discussion of schemas, instances and namespaces.

The whole matter of instance/schema connections is still under discussion: the WG has not reached consensus in this area. The referenced section does give some indication of where our thinking in this area is going. <!DOCTYPE schema PUBLIC '-//W3C//DTD XML Schema Version 1.0//EN' SYSTEM '&XSP1.URI;.dtd' > <schema targetNS='http://purl.org/metadata/dublin_core' version='M.n' xmlns='&XSP1.base;'> ... </schema>

Note that the abstract syntax xmlSchemaRef is realised via a default namespace declaration in the concrete syntax.

Although the schema above is a complete XML document, schema need not be the document element, but can appear within other documents. Indeed there is no requirement that a schema be derived from a (text) document at all: it could be built 'by hand' via e.g. a DOM-conformant API.

The schema's model property is discussed in . The schema's export, import and include properties are discussed in .

The schema's declarations and definitions, discussed in detail in , provide for the creation of new schema components:

Summary of Definitions and Declarations datatypeDefn NCName datatypeSpec archetypeDefn NCName archetypeSpec elementDecl NCName elementSpec modelGroupDefn NCName modelGroupSpec attrGroupDefn NCName attrGroupSpec entityDecl NCName entitySpec notationDecl NCName notationSpec

The following illustrates the basic model for declaring or defining all &XSP1; components:

<datatype name='myDatatype'> ... </datatype> <archetype name='myType'> ... </archetype> <element name='myElement'> ... </element> <attrGroup name='myAttrGroup'> ... </attrGroup> <modelGroup name='myModelGroup'> ... </modelGroup> <notation name='myNotation' ... /> <textEntity name='myTextEntity'> ... </textEntity> <externalEntity name='myExternalEntity' ... /> <unparsedEntity name='myUnparsedEntity' ... /> </schema>

When creating a component, we establish an association between its name and the specification for that component. Each new component therefore creates a new entry in the symbol space for that kind of component.

The Constraint on Schemas obtains.

This draft does not deal with the requirement "for addressing the evolution of schemata" (see ).

The Document and its Root

We have not so far seen any need to reconstruct the XML 1.0 notion of root. For the connection from document instances to schemas, see and .

References to Schema Constructs

Uniform means are provided for reference to a broad variety of schema constructs, both within a single schema and to features imported () from external schemas. The name used to reference any component of &XSP1; from within a schema consists of an NCName and an optional schemaRef, a reference to an external schema. In a few cases, some qualification may be added to a reference: this is made clear as the individual reference forms are introduced below.

Example: Component Names and References schemaRef (schemaAbbrev | schemaName) schemaAbbrev NCName schemaName URI typeRef archetypeRef | datatypeRef datatypeRef datatypeName datatypeQual datatypeName NCName schemaRef? archetypeRef typeName archetypeName NCName schemaRef? elementRef elementName elementName NCName schemaRef? attrGroupRef attrGroupName attrGroupQual attrGroupName NCName schemaRef? modelGroupRef modelGroupName modelGroupName NCName schemaRef? entityRef entityName entityName NCName schemaRef? notationRef notationName notationName NCName schemaRef?

The abstract syntax above characterizes the reference mechanisms used in this specification.

<element type='Address'/> <element type='BLOCKQUOTE' schemaAbbrev='XHTML'/> <attribute type='quantity' schemaName='http://www.w3.org/xsl.xsd'/>

The first of these is a local reference, the other two refer to schemas elsewhere. The BLOCKQUOTE example assumes the schemaAbbrev XHTML has been declared for import; the template example similarly assumes that the given (imaginary as of this writing) URL has been declared for import. See for a discussion of importing.

The Constraint on Schemas obtains.

The Constraint on Schemas obtains.

The identify definition wrt schema-validity obtains.

The Constraint on Schemas also obtains.

Types, Elements and Attributes

Like XML 1.0 DTDs, &XSP1; provides facilities for constraining the contents of elements and the values of attributes, and for augmenting the information set of instances, e.g. with defaulted values and type information. We refer hereafter to the combination of schema constraints and information set contributions with the abbreviation SC. Compared to DTDs, &XSP1; provides for a richer set of SCs, and improved capabilities for sharing SCs across sets of elements and attributes.

Datatype Definition

We start with the simple datatypes whose expression in XML documents consists entirely of character data. As in the current draft of &XSP2;, wherever we speak of datatypes in this draft, we shall mean these simple datatypes.

Datatypes datatypeDefn NCName datatypeSpec datatypeSpec [defined by XML Schemas: Datatypes] exportControl? datatypeQual specialize? valueConstraint? specialize facet+ facet is defined by XML Schemas: Datatypes. It might be a range restriction, length constraint, etc. valueConstraint default | fixed datatypeRef datatypeName datatypeQual datatypeName NCName schemaRef? schemaRef (schemaAbbrev | schemaName) schemaAbbrev NCName schemaName URI

&XSP1; incorporates the datatype specification mechanisms defined by in order to express SCs on attribute values and the contents of elements consisting entirely of character data.

The production for datatypeSpec above serves to indicate where this chapter connects with &XSP2;. exportControl is defined in . The concrete syntax displayed below is copied from . Most of the elements are for specifying facets: they are all optional and may appear in any order after the basetype element.

The other productions provide for using datatypes once they have been defined, see below under contentType and attribute.

We assume that it is appropriate to allow for some local specialization of datatypes at the point of use, and provide for that here (specialize).

As explained in , a schemaRef, if included, allows for the referenced definition to be located in some other schema.

0 12pt ]]>

The first attribute example references the definition above it. The second references a datatype pre-defined by &XSP2;. The third references a datatype in an (imaginary) XSL schema and fixes its value.

See previous note on the type definition issue.

The satisfy-dt definition wrt schema-validity obtains.

The Schema Information Set Contribution obtains.

Archetype Definition

Archetype specifications gather together all SCs pertinent to elements in instance documents, their attributes and their contents. They are called archetypes because there may be more than one element declaration that shares the same SCs (see ), and which therefore can be constrained by a common archetype.

Archetypes archetypeDefn NCName archetypeSpec archetypeSpec refinement* contentType ( attribute | attrGroupRef )* model exportControl contentType datatypeRef | contentModel | modelGroupRef model open | refinable | closed archetypeRef archetypeName archetypeName NCName schemaRef? refinement typeRef

The first three productions above provide the basic structure of the specification, and the last two provide for reference to the things specified. But note that the name of an archetype is not ipso facto the name of elements whose appearance in instances will be associated with the SCs of that archetype. The connection between an element name and an archetype is made by an elementDecl, see below.

Alongside for permitted attributes, SCs for contents are specified in an archetype (contentType). For elements which may contain only character data, this is by reference to a . Note that doing this by way of datatypeRef allows for specialization and even defaulting in a manner similar to attribute values. For other kinds of elements, an is required.

The extension of defaulting to element content is tentative.

0 2.54 0 2.54cm ]]>

Two approaches to defining an archetype for length: one with character data content constrained by a qualified reference to a built-in datatype, and one attribute, the other using two elements.

The way in which the concrete syntax defined and illustrated above realises the abstract syntax is not straightforward, because it is optimised to make simple cases simple. The datatypeQual option is allowed only if a type attribute is present. Similarly, the schemaName or schemaAbbrev, the default and the fixed attributes are allowed only if a type attribute is present. Finally, if a type attribute is present, it must reference a datatype, and the content attribute must be textOnly (or absent, in which case it defaults to textOnly). This is to handle the main alternation in the abstract syntax for contentType, which allows either (possibly locally qualified) reference to a datatype or a content model.

See previous note on the type definition issue.

The Constraint on Schemas obtains.

The Constraint on Schemas obtains.

The attr-decl-set definition wrt schema-validity obtains.

The attr-fullname definition wrt schema-validity obtains.

The Constraint on Schemas obtains.

The satisfy-as definition wrt schema-validity obtains.

The Schema Information Set Contribution obtains.

Attribute Declaration

Attribute declarations associate a name (which will appear as an attribute in start tags in instances) with SCs for the presence and value thereof.

Attributes attribute NCName datatypeRef? required exportControl datatypeRef datatypeName datatypeQual datatypeQual specialize? valueConstraint? valueConstraint default | fixed datatypeName NCName schemaRef? schemaRef (schemaAbbrev | schemaName)

The datatypeRef productions are repeated here for easy reference.

Attribute declarations provide for:

Requiring instances to have attributes;

Constraining attribute values to express a datatype.

0 ]]>

Four attributes are declared: one with no explicit SCs at all; two declared by reference to a built-in datatype, one with a default and a subrange qualification and one required to be present in instances; and one with a fixed value.

The maxOccurs attribute is FIXED at 1 for all attributes. Consistent with this, minOccurs can only be 0 or 1.

When attribute declarations are used in an archetype specification, each archetype provides its own symbol space for attribute names. E.g. an attribute named title within one archetype need not have the same datatypeRef as one declared within another archetype.

The attr-satisfy definition wrt schema-validity obtains.

What is the default attribute datatypeSpec?

The satisfy-attrs definition wrt schema-validity obtains.

The Schema Information Set Contribution obtains.

We've got a problem with namespace declarations: they're not attributes at the infoset level, so they can appear without compromising validity, except if there is a fixed or required declaration, and defaults should have the apparently desired effect. I.e., if a schema declares an attribute whose name is xmlns with a default or fixed value, does it change the infoset? Or if we allow QNames as such to be declared, xmlns:foo.

Attribute Group Definition *

&XSP1; can name a group of attributes so that they may be incorporated as a whole into archetype definitions:

Attribute groups attrGroupDefn NCName attrGroupSpec attrGroupSpec attribute* exportControl attrGroupRef attrGroupName attrGroupQual attrGroupName NCName schemaRef? attrGroupQual attribute

Attribute group definitions provide a construct to replace some uses of parameter entities.

<attrGroup name='myAttrGroup'> <attribute .../> ... </attrGroup> <archetype name='myelement' content='empty'> <attrGroupRef name='myAttrGroup'/> </archetype>

Define and refer to an attribute group. The effect is as if the attribute declarations in the group were present in the archetype definition.

There needs to be a Constraint on Schema which constrains the attributes which appear with an attrGroupRef: the name is the same as one of the attributes in the group, datatype and defaulting preserves substitutability, etc. There needs to be some discussion of what happens in case of name conflict between attrs as a result of an attr group ref.
Element Content Model

When content of elements is not constrained by reference to a datatype (), it can have any, empty, element-only or mixed content. In the latter cases, the form of the content is specified in more detail.

Content model contentModel any | empty | mixed | elemOnly

A content model constrains the element content of an archetype specification: it says nothing about attributes.

Content models do not have names, but appear as a part of the definition of an archetype, which does have a name. Model groups can be named and used by name, see below.

The satisfy-cm definition wrt schema-validity obtains.

Mixed Content

A content model for mixed content provides for mixing elements with character data in document instances. The allowed elements are named, but neither their order nor their number of occurrences is constrained.

Mixed content mixed ( elementRef | archetypeRef | elementDecl )*

The elementRefs and elementDecls determine the elements that may appear as children along with character data. For the interpretation of archetypeRef in this context, see .

<archetype content='mixed'> <element ref='name1'/> <element ref='name2'/> <element ref='name3'/> </archetype>

Allows character data mixed with any number of name1, name2 and name3 elements.

The fact that mixed allows for there to be no elementRefs or elementDecls makes it similar to XML 1.0's Mixed production. Indeed an empty mixed is the only way a schema can allow character data content with no datatype constraint at all.

The Constraint on Schemas obtains.

See for discussion and examples of the appearance of elementDecl above.

The satisfy-mixed definition wrt schema-validity obtains.

Element-Only Content

A content model for element-only content specifies only child elements (no immediate character data content other than white space is allowed). The content model consists of a simple grammar governing the allowed types of child elements and the order in which they must appear.

Element-only content elemOnly modelElt modelElt occurs ( modelGroup | modelGroupRef | elementRef | archetypeRef | elementDecl ) occurs minOccurs maxOccurs modelGroup richModelGroup | simpleModelGroup richModelGroup compositor modelElt modelEltSeq compositor sequence | choice modelEltSeq modelElt modelEltSeq? simpleModelGroup all simpleModelElt simpleModelEltSeq simpleModelElt elementRef | elementDecl | archetypeRef simpleModelEltSeq simpleModelElt simpleModelEltSeq? I'm unclear what the status of collection is after the Montreal votes, for the time being it's out.

The grammar for element-only content is built on model elements and model groups (modelElt and modelGroup above). A model element provides for some number of occurrences in an instance of either a single element (via elementRef or elementDecl) or a group of elements (via modelGroup or modelGroupRef). A model group is two or more model elements plus a compositor.

A compositor for a model group specifies for a given group whether it is a sequence of its model elements, a choice between its model elements or a set of its model elements which must appear in instances (this is the case for the implicit 'and' compositor, which is associated with the simpleModelGroup production. These options reconstruct the XML 1.0 , connector, the XML 1.0 | connector and the SGML & connector respectively. In the first case (sequence) all the model elements must appear in the order given in the group; in the second case (choice), exactly one of the model elements must appear in the element content; and in the third case (all), all the model elements, which are restricted in this case only to unqualified elementRefs and elementDecls, must appear in the element content, but may appear in any order.

The occurs specification governs how many times the instance material allowed by a modelElt may occur at that point in the grammar, but note that the components of a group whose compositor is (implicitly) 'all' are not qualified, and therefor call for exactly one appearance of the element they identify.

See for further discussion and examples of the appearance of elementDecl within modelElt above.

For the interpretation of archetypeRef in this context, see .

The satisfy-eo definition wrt schema-validity obtains.

The Constraint on Schemas obtains.

The Constraint on Schemas obtains.

Should this compatibility constraint be preserved?

Named Model Group *

This reconstructs another common use of parameter entities.

Named model groups modelGroupDefn NCName modelGroupSpec modelGroupSpec ( modelGroup | modelGroupRef ) exportControl modelGroupRef modelGroupName modelGroupName NCName schemaRef? <modelGroup name='myModelGroup'> <element ref='myelement'/> </modelGroup> <element name='myelement'> <archetype> <modelGroupRef name='myModelGroup'/> <attribute ...>. . .</attribute> </archetype> </element> <element name='anotherelement'> <archetype> <group order='choice'> <element ref='yetAnotherelement'/> <modelGroupRef name='myModelGroup'/> </group> <attribute ...>. . .</attribute> </archetype> </element>

A minimal model group is defined and used by reference, first as the whole content model, then as one alternative in a choice.

Element Declaration

An element declaration associates an element name with a type, either by reference or by incorporation.

Element declaration elementDecl NCName elementSpec elementSpec ( typeRef | archetypeSpec | datatypeSpec) exportControl global? typeRef archetypeRef | datatypeRef elementRef elementName elementName NCName schemaRef?

An element declaration associates a name with a specification. This name will appear in tags in instance documents; the specification provides SCs on the form of elements tagged with the given name. An element declaration whose elementSpec is an archetypeSpec is comparable to an <!ELEMENT ...> declaration in an XML 1.0 DTD.

elementSpec not only allows for element declarations to associate a name with an archetypeSpec (by reference or inclusion), but also allows the reference or specification to be for a datatype, with the implication that no attributes are allowed in instances and the text-only content will be constrained appropriately.

elementRef and elementName provide for top-level element declarations to be referenced by name from content models.

As noted above element names are in a separate symbol space from the symbol spaces for the names of types, so there can (but need not be) an archetype or datatype with the same name as a top-level element.

In the case of ambiguity of type reference, that is when the typeRef option is used and there are both a datatype and an archetype of the referenced name in the relevant schema, the ambiguity is resolved in favour of the archetype.

See previous note on the ambiguity issue.

The elt-fullname definition wrt schema-validity obtains.

An elementDecl may appear both at the top level of a schema and within a modelElt. See above ( and ) for where this is allowed. This declares a locally-scoped association between an element name and a type. As with attribute names, locally-scoped element names reside in symbol spaces local to the archetype that defines them. Note however that archetype and datatype names are always top-level names within a schema, even when associated with locally-scoped element names.

It is not yet clear whether a type defined implicitly by the appearance of a archetypeSpec or datatypeSpec directly within an elementSpec, or by the use of a typeRef which refers to a datatype, will have an implicit name, or if so what that name would be.

<element name='myelement' type='myDatatype'/> <element name='et0' type='myType'/> <element ref='et1'/> <element name='et1'> <archetype order='all'> <element . . . /> . . . <attribute ...>. . .</attribute> </archetype> </element> <element name='et2'> <archetype content='any'/> </element> <element name='et3'> <archetype content='empty'> <attribute ...>. . .</attribute> </archetype> </element> <element name='et4'> <archetype order='choice'> <element . . . /> . . . <attribute ...>. . .</attribute> </archetype> </element> <element name='et5'> <archetype order='seq'> <element . . . /> . . . <attribute ...>. . .</attribute> </archetype> </element> <element name='et6'> <archetype model='open' content='mixed'/> </element>

A pretty complete set of alternatives. Note the last one is intended to be equivalent to the idea sometimes called WFXML, for Well-Formed XML: it allows any content at all, whether defined in the current schema or not, and any attributes.

<element name='contextOne'> <archetype order='seq'> <element name='myLocalelement' type='myFirstType'/> <element ref='globalelement'/> </archetype> </element> <element name='contextTwo' <archetype order='seq'> <element name='myLocalelement' type='mySecondType'/> <element ref='globalelement'/> </archetype> </element>

Instances of myLocalelement within contextOne will be constrained by myFirstType, while those within contextTwo will be constrained by mySecondType.

The possibility that differing attribute declarations and/or content models would apply to elements with the same name in different contexts is an extension beyond the expressive power of a DTD in XML 1.0.

The Constraint on Schemas obtains.

The Constraint on Schemas obtains.

The satisfy-ed definition wrt schema-validity obtains.

The ind-valid definition wrt schema-validity obtains.

The satisfy-etr definition wrt schema-validity obtains.

Archetype Refinement *

This chapter articulates what has only been hinted at above, namely a considerable increase in the power and expressiveness of schema declarations, by explaining what was provided for in the abstract syntax in the previous section, but not explained much if at all at that point.

We provide for the refinement of archetypes defined in a schema. An archetype definition may identify one or more other archetypes from which it specifies the creation of a (joint) refinement.

The balance of this chapter has been withdrawn, pending further discussion in the WG. A Task Force created from within the WG has investigated a range of issues and options for implementing the desired functionality, as called for in the . The Task Force has produced a report , which will form the basis of a design to be filled in here.

Graveyard for stale syntax, here to avoid breaking IDREFs elsewhere *

an archetype AT1 is said to refine an archetype AT2 if and only if AT1 is declared to refine either AT2 or (recursively) some archetype that refines AT2. AT2 is then said to be an ancestor of AT1. The effective constraints are the union of the explicit and the acquired.

Entities and Notations * Entities and notations entityDecl NCName entitySpec entitySpec ( textEntitySpec | externalEntitySpec | unparsedEntitySpec ) exportControl? textEntitySpec string-value externalEntitySpec systemID publicID? exportControl? unparsedEntitySpec systemID notationRef publicID? exportControl? entityRef entityName entityName NCName schemaRef? notationDecl NCName notationSpec notationSpec systemID notationRef publicID? exportControl? systemID URI publicID see notationRef notationName notationName NCName schemaRef? Internal Parsed Entity Declaration *

Internal parsed entities are a feature of XML that enables reuse of text fragments by direct reference in an instance document.

In &XSP1; documents, internal parsed entities are declared by using the textEntitySpec production.

<textEntity name='flavor'>Fresh mint</textEntity'>

flavor can now be used in an entity reference in instances of the containing schema.

See for SCs covering entities and entity references.

External Parsed Entity Declaration *

External parsed entities are a feature of XML that offers a method for including well-formed XML document fragments, including text and markup, by direct reference to the storage object of the parsed entity.

In schemas, external parsed entities are declared by using the externalEntitySpec production.

<externalEntity name='FrontMatter' system='FrontMatter.xml' /> <externalEntity name='Chapter1' system='chapter1.xml' /> <externalEntity name='Chapter2' system='Chapter2.xml' /> <externalEntity name='BackMatter' system='BackMatter.xml' />

These four external entities represent the supposed contents of a book:

<book> &FrontMatter; &Chapter1; &Chapter2; &BackMatter; </book>

In an instance, the external entities take their familiar XML form. The processor expands the entities for their content.

Again, See for SCs covering entities and entity references.

Unparsed Entity Declaration *

External unparsed entities are a feature of XML that offers a baroque method for including binary data by indirect reference to both the storage object and the the notation type of the unparsed entity. In schemas, external parsed entities may be declared by using the unparsedEntitySpec production.

<unparsedEntity name='SKU-5782-pic' system='http://www.vendor.com/SKU-5782.jpg' notation='JPEG' /> <picture location='SKU-5782-pic'/>

The picture element carries an attribute which is (presumably) governed by the unparsed entity declaration.

The Schema Validity Constraint obtains.

There are lots of gaps and little problems in this design for unparsed entities.

Notation Declaration *

A notation may be declared by specifying a name and an identifier for the notation. A notation may be referenced by name in a schema as part of an external entity declaration.

<notation name='jpeg' public='image/jpeg' system='viewer.exe' /> <element name='picture> <archetype> <attribute name='entity' type='NOTATION'/> </archetype> </element> <picture entity='SKU-5782-pic'/>

The notation need not ever be mentioned in the instance document.

We need to synchronise with XML Schemas: Datatypes regarding how we declare attributes as unparsed entities!

Schema Composition and Namespaces * Introduction and TF report summary *

This chapter describes facilities to provide for validation of namespace-qualified instance document elements and attributes, and potentially (subject to enhancements to the Namespaces recommendation), entities and notations.

'Namespaces in XML' provides an enabling framework for modular composition of schemas. From that document:

We envision applications of Extensible Markup Language (XML) where a single XML document may contain elements and attributes (here referred to as a 'markup vocabulary') that are defined for and used by multiple software modules. One motivation for this is modularity; if such a markup vocabulary exists which is well-understood and for which there is useful software available, it is better to re-use this markup rather than re-invent it. Such documents, containing multiple markup vocabularies, pose problems of recognition and collision. Software modules need to be able to recognize the tags and attributes which they are designed to process, even in the face of 'collisions' occurring when markup intended for some other software package uses the same element or attribute name. These considerations require that document constructs should have universal names, whose scope extends beyond their containing document. This specification describes a mechanism, XML Schema namespaces, which accomplishes this.

&XSP1; provides facilities to enable declaration and modular composition of schemas.

The balance of this section as it appeared in the previous public WD has been withdrawn, pending further discussion in the WG. A Task Force created from within the WG has investigated a range of issues and options for implementing the desired functionality. The Task Force has produced a report , which will form the basis of a design to be filled in here.

I've chosen to include here a brief summary of the expected TF report, addressing the instance->schema connection issue, on the grounds that confusion is rampant in the rest of the world wrt this issue, and we will benefit both ourselves and others by signalling our thinking here as soon as possible.

The TF report recommends a layered approach, where the base layer simply addresses the process of schema validation where the element information item to be validated and the schema to validate it with are known. The second layer discusses mechanisms by which processors may locate schemas, but emphasises that this is always in the end an processor- and environment-dependent process. The following candidate mechanisms are identified:

The namespace URI of the item to be validated is dereferenced and yields a schema;

The namespace URI of the item to be validated is dereferenced and yields a package. A standard property of the package tells what kind of package it is and hence how to go about getting schema info out of it. We anticipate a great range of flexibility in the structuring and content of packages: schemas will certainly not be the only thing in them. All that matters to us is that we can get a schema out of them;

A URI is provided via a pre-defined attribute from the XML Schema namespace, which is dereferenced and yields a schema (or a package);

The namespace URI of the item to be validated is looked up via a catalogue or other binding mechanism, either locally or remotely, and yields a schema (or a package).

It is worth noting that the TF has not reached consensus on whether the above list should be understood as ordered, that is, in the case where more than one is viable, should we identify a precedence.

Graveyard for stale syntax, here to avoid breaking IDREFs elsewhere * Exporting Schema Constructs Export export allDatatypes? allArchetypes? allElements? allModelGroups? allAttributeGroups? allEntities? allNotations? allDatatypes boolean allArchetypes boolean allElements boolean allModelGroups boolean allAttributeGroups boolean allEntities boolean allNotations boolean exportControl boolean Schema Import Import import schemaAbbrev schemaName importRestrictions? Import Restrictions Import restrictions importRestrictions allDatatypes? allArchetypes? allElements? allModelGroups? allAttributeGroups? allEntities? allNotations? component* component componentName componentType componentName NCName componentType datatype | archetype | element | attrGroup | modelGroup | entity | notation Schema Inclusion Include include schemaRef allDatatypes? allArchetypes? allElements? allModelGroups? allAttributeGroups? allEntities? allNotations? component* Associating Instance Document Constructs with Corresponding Schemas
Documenting schemas *

Documentation facilities have purposely been left out of this draft of the XML Schema Definition Language specification. The editors chose to concentrate on other topics. It is anticipated that explanation elements will be provided for within any of the Schema elements. Their purpose is to encapsulate documentation for the elements within which they are contained. Elements for narrative exposition at the top level of a schema have also been proposed.

Proposals for XML Schema documentation include defining a custom set of elements, allowing any content at all, allowing all or part of , DocBook or TEI. There are good arguments for each of these proposals.

The Working Group must identify its requirements and constraints.

Conformance -- OUT OF DATE *

This draft includes extensive discussion of conformance and validity checking, but rules for dealing with errors are missing. In future, we must distinguish errors from fatal errors, and clarify rules for dealing with both.

Schema Validity *

This section is not up to date or in sync with the rest of the document, but is included here to avoid breaking huge numbers of references

We approach the definition of schema validity one step at a time. In the definitions below we deal primarily in terms of information sets, rather than the documents which give rise to them: see for definitions of item, RUE and information set.) Please note that the formal definitions below are explicitly not couched in processing terms: they describe properties of an information set, but do not tell you how to check an information set to see if it has those properties.

First we have to get to the schema(s) involved. This is slightly tricky, as not all namespace declarations will resolve to schemas, and not everything that purports to be a schema will be one.

A URI is said to nominate a schema if it resolves to an element item in the information set of a well-formed XML 1.0 document whose local name is schema and whose namespace item's URI identifies either

this specification or one of its successors,

the XML Schema 1.0 DTD (or the equivalent DTD from a successor to this specification)

or

The XML Schema 1.0 schema (or the equivalent schema from a successor to this specification).

A URI is said to resolve successfully to a schema if it nominates a schema, and the element item it resolves to represents an XML schema, that is:

If it were the document element item of an information set corresponding to an XML document whose DOCTYPE identified the XML Schema 1.0 DTD (or the equivalent DTD from a successor to this specification) as its DTD, that document would be valid per XML 1.0;

it and its descendants satisfy all Constraints on Schemas stated in this specification.

An element item is schema-ready if the URI of any of its namespace declaration items which nominates a schema resolves successfully to a schema.

Namespace items associated with namespace declarations have disappeared from the most recent version . Several WGs need them, we expect they'll be back, otherwise we can reconstruct what we need from element and attribute namespace items alone with some effort.

A document is schema-ready if every element item anywhere in its information set is schema-ready.

Note that this means that documents with no namespace declarations, or only namespace declarations which do not nominate schemas are none-the-less schema-ready.

We say an element item is schema-governed if its name is in a namespace, and the URI of the information item for that namespace resolves successfully to a schema.

We use the name schema root for any element item which is schema-governed and which is either

the document element

or

the daughter of an element which is not schema-governed.

The provision within &XSP1; of a mechanism for defining parsed entities presents problems for the relationship between schema-validity and XML 1.0 well-formedness, since references to entities declared only in a schema are undefined from the XML 1.0 perspective. Strictly speaking, a well-formed XML document may contain references to undefined entities only if it is declared as standalone='no' and contains either an external subset or one or more references to external parameter entities in their internal subset. We get around this by defining a nearly well-formed XML document to be one which either is well-formed per XML 1.0, or which fails to be well-formed only because of undefined general entity references, but which would be well-formed if it were standalone='no' and identified an external subset. We consider this justified on the grounds that the use of a nam