W3C

XML Schema Patterns for Common Data Structures Version 1.0

W3C Working Draft 12 May 2006

This version:
http://www.w3.org/TR/2006/WD-xmlschema-patterns-20060512/
Latest version:
http://www.w3.org/TR/xmlschema-patterns
Editors:
Paul Downey, BT
Yves Lafon, W3C

Abstract

This specification provides a set of simple XML Schema 1.0 patterns which may be used to describe XML representations of commonly used data structures. The data structures described are intended to be independent of any particular programming language or database or modelling environment.

Status of this Document

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 document is a First Public Working Draft and has been produced by the XML Schema Patterns for Databinding Working Group, part of the Web Services Activity in the W3C Architecture Domain. The authors of this document are the members of the W3C XML Schema Patterns for Databinding Working Group.

The document is in its early stage, readers should expect lots of changes and additions. A list of issues currently under consideration is available from the XML Schema Patterns for Databinding Working Group home page.

Please send comments about this document to public-xsd-databinding-comments@w3.org (with public archive). Discussions on this specification should take place on the :public-xsd-databinding@w3.org (with public archive)

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.

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.


Table of Contents

1. Introduction
    1.1 Notational Conventions
    1.2 Namespaces
    1.3 Conformance
2. Data Types & Structures
    2.1 String Value
    2.2 Boolean Value
    2.3 Decimal Value
    2.4 Null Value
    2.5 Default Value
    2.6 Enumeration
    2.7 Collection
    2.8 Vector
    2.9 Inherited Collection
3. Schema Patterns
    3.1 Target Namespace
    3.2 Qualified Local Elements
    3.3 Qualified Attributes
    3.4 String
    3.5 Boolean
    3.6 Int
    3.7 String Enumeration
    3.8 Collection
    3.9 Optional Element
    3.10 Nillable Element
    3.11 Nillable-Optional Element
    3.12 Simple List
    3.13 Wrapped Repeated Element
    3.14 Repeated Element
4. References
    4.1 Normative References
    4.2 Informative References

Appendix

A. Acknowledgements (Non-Normative)


1. Introduction

This specification provides a set of example XML Schema structures [XML Schema Part 1: Structures Second Edition] and types [XML Schema Part 2: Datatypes Second Edition] which may be used to exchange commonly used data structures in the form of an XML document.

Authors of XML Schema 1.0 documents may find these patterns useful in providing a better user experience for consumers of schemata using data mapping and binding tools.

Implementers of tools which map or bind data structures to and from XML may find these patterns useful to represent simple and common place constructs. Ensuring tools recognise at least these simple XML Schema 1.0 patterns and present them in terms most appropriate to the specific language, database or environment may provide an improved user experience when using data mapping and binding tools.

This specification should not be used to constrain the use of the XML Schema 1.0 Recommendation. An XML Schema 1.0 processor should continue to provide support the whole of the XML Schema 1.0 Recommendation.

Whilst it is not possible to guarantee that schemata produced using these patterns will give a good user experience with the universal set of databinding tools, the patterns contained in this specification have been tested with a number of differnet tools covering a variety of different programming languages and environments.

1.1 Notational Conventions

The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this specification are to be interpreted as described in RFC 2119 [[RFC 2119]].

The notational convention of WS-Security [[WS-Security]] is used to describe XML content. Specifically, each member of an Element Information Item's [children] or [attributes] property is described using an XPath-like notation (e.g., /x:MyHeader/x:SomeProperty/@value1). The use of {any} indicates the presence of an element wildcard (<xs:any/>). The use of @{any} indicates the presence of an attribute wildcard (<xs:anyAttribute/>).

Editorial note: pdowney 2006-04-26
Each pattern is defined using a series of {REQUIRED} or {OPTIONAL} XPath assertions which will be used to generate a validation tool. The tool is likely to be implemented using Schematron, subject to ISSUE-12

This specification presents a number of design issues an author of an XML Schema may wish to consider. Though the patterns presented by this specification are expected to be testable by tools to highlight possible interoperability problems with databinding and mapping tools, considerations have no impact on conformance.

Editorial note: pdowney 2006-04-26
It's likely that a class of Design Considerations may result in "warnings" from a validation tool, in particular when a pattern is known not be to well supported by niche or an older versions of mainstream tools - ISSUE-35.

1.2 Namespaces

This specification uses a number of namespace prefixes throughout; they are listed in Table 1-1. Note that the choice of any namespace prefix is arbitrary and not semantically significant (see [[XMLNS]]).

Table 1-1. Prefixes and Namespaces used in this specification
Prefix Namespace
xs http://www.w3.org/2001/XMLSchema
xsi http://www.w3.org/2001/XMLSchema-instance
soap11 http://schemas.xmlsoap.org/soap/envelope/
soap12 http://www.w3.org/2003/05/soap-envelope
wsdl11 http://schemas.xmlsoap.org/wsdl/
wsdl20 http://www.w3.org/2005/08/wsdl
ex http://www.w3.org/2002/ws/databinding/example

1.3 Conformance

Editorial note: pdowney 2006-03-27
Section on what it means to conform to this Recommendation required - a conformant schema be constructed only from the patterns within this specification.

2. Data Types & Structures

2.1 String Value

Definition
-
Patterns

2.2 Boolean Value

Definition
A boolean has the value space required to support the mathematical concept of binary-valued logic: {true, false}.
Patterns

2.3 Decimal Value

Definition
-
Patterns

2.4 Null Value

Definition
A special value used to represent an "unknown", "missing", "not applicable", "uninitialised" or "undefined value".

Design Consideration

Several different patterns are provided for expressing the absence of a value, however minOccurs and nillable. Advice on when to use a given pattern is the subject of ISSUE-37.

Patterns
Editorial note: pdowney 2006-03-27
This section is likely to change subject to the resolution of ISSUE-7.

2.5 Default Value

Definition
A preselected value used by when no alternative is explicitly specified.
Patterns
-

2.6 Enumeration

Definition
A type whose definition contains an exhaustive list of possible values.
Patterns

2.7 Collection

Definition
A collection of data items, typically contained by a programming language "object", "class", "structure", or "record".
Patterns

2.8 Vector

Definition
A vector is an ordered sequence of items of the same type. This construct appears in programming languages as an array or list.
Patterns

2.9 Inherited Collection

Definition
-
Patterns
-
Editorial note: pdowney 2006-04-21
Section resulting from resolution of ISSUE-21

3. Schema Patterns

3.1 Target Namespace

Definition

An XML Schema document conforming to this specification MUST define a targetNamesapce attribute.

  • {REQUIRED} @targetNamespace
Examples
Example 1: Schema with a targetNamespace Value
<xs:schema
    targetNamespace="http://www.w3.org/2002/ws/databinding/testsuite/documents/" 
    elementFormDefault="qualified"/>
          

3.2 Qualified Local Elements

Definition

An XML Schema document conforming to this specification MUST namespace qualify all locally defined elements using a schema element elementFormDefault attribute value of 'qualified'.

  • {REQUIRED} @elementFormDefault = 'qualified'
Examples
Example 2: Schema with a Qualified elementFormDefault Value
<xs:schema
    targetNamespace="http://www.w3.org/2002/ws/databinding/testsuite/documents/" 
    elementFormDefault="qualified"/>
          

3.3 Qualified Attributes

Definition

Attributes defined by a conformant Schema may be either be namespace qualified or unqualified under the control of the schema element attributeFormDefault attribute.

  • {OPTIONAL} @attributeFormDefault = 'qualified' or @attributeFormDefault = 'unqualified'
Examples
Example 3: Schema with the Default attributeFormDefault Value
<xs:schema
    targetNamespace="http://www.w3.org/2002/ws/databinding/testsuite/documents/" 
    elementFormDefault="qualified"/>
          
Example 4: Schema with an Unqualified attributeFormDefault Value
<xs:schema
    targetNamespace="http://www.w3.org/2002/ws/databinding/testsuite/documents/" 
    attributeFormDefault="unqualified"
    elementFormDefault="qualified"/>
          
Example 5: Schema with a Qualified attributeFormDefault Value
<xs:schema
    targetNamespace="http://www.w3.org/2002/ws/databinding/testsuite/documents/" 
    attributeFormDefault="qualified"
    elementFormDefault="qualified"/>
          

3.4 String

Definition

An element or attribute defined by a conformant Schema may be of the type 'xs:string'.

Examples
Example 6: StringValue
 
<xs:element name="stringElement" type="xs:string"/>
          
Instance:
<ex:stringElement>The World Wide Web Consortium (W3C)</ex:stringElement>
Instance:
<ex:stringElement/>
Example 7: StringAttribute
 
<xs:attribute name="stringAttribute" type="xs:string"/>
          
Instance:
ex:stringAttribute="The World Wide Web Consortium (W3C)"
Instance:
ex:stringAttribute=""

3.5 Boolean

Definition
-
Examples
Example 8: BooleanValue
 
<xs:element name="booleanElement" type="xs:boolean"/>
          
Instance:
<ex:booleanElement>true</ex:booleanElement>
Instance:
<ex:booleanElement>false</ex:booleanElement>
Instance:
<ex:booleanElement>1</ex:booleanElement>
Instance:
<ex:booleanElement>0</ex:booleanElement>
Example 9: BooleanAttribute
 
<xs:attribute name="booleanAttribute" type="xs:boolean"/>
          
Instance:
ex:booleanAttribute="true"
Instance:
ex:booleanAttribute="false"
Instance:
ex:booleanAttribute="1"
Instance:
ex:booleanAttribute="0"

3.6 Int

Definition
-
Examples
Example 10: IntElement
 
<xs:element name="intElement" type="xs:int"/>
          
Instance:
<ex:intElement>42</ex:intElement>
Instance:
<ex:intElement>-42</ex:intElement>
Example 11: IntAttribute
 
<xs:attribute name="intAttribute" type="xs:int"/>
          
Instance:
ex:intAttribute="42"
Instance:
ex:intAttribute="-42"

3.7 String Enumeration

Definition

Design Consideration

text from resolution of ISSUE-6

Examples
Example 12: Beatle
 
<xs:element name="beatle" type="ex:Beatle"/>

<xs:simpleType name='Beatle' >
  <xs:restriction base='xs:string' >
   <xs:enumeration value='John' />
   <xs:enumeration value='Paul />
   <xs:enumeration value='George' />
   <xs:enumeration value='Stuart' />
   <xs:enumeration value='Pete' />
   <xs:enumeration value='Ringo' />
  </xs:restriction>
</xs:simpleType>
            
Instance:
<ex:beatle>Paul</ex:beatle>
Instance:
<ex:beatle>John</ex:beatle>
Instance:
<ex:beatle>Ringo</ex:beatle>

3.8 Collection

Definition
-
Examples
Example 13: Product
<xs:element name="product" type="ex:Product"/>

<xs:complexType name="Product">
  <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="shade" type="xs:string"/>
    <xs:element name="length" type="xs:int"/>
  </xs:sequence>
  <xs:attribute name="id" type="xs:string" />
  <xs:attribute name="inStock" type="xs:int" />
</xs:complexType>
          
Instance:
<ex:product id="6026" inStock="232">
  <ex:name>Widget</ex:name>
  <ex:shade>Light Blue</ex:shade>
  <ex:length>33</ex:length>
</ex:product>
Instance:
<ex:product inStock="52" id="6026">
  <ex:name>Widget</ex:name>
  <ex:shade>Green</ex:shade>
  <ex:length>1233</ex:length>
</ex:product>
Example 14: ProductBag
<xs:element name="productBag" type="ex:ProductBag"/>

<xs:complexType name="ProductBag">
  <xs:all>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="shade" type="xs:string"/>
    <xs:element name="length" type="xs:int"/>
  </xs:all>
  <xs:attribute name="id" type="xs:string" />
  <xs:attribute name="inStock" type="xs:int" />
</xs:complexType>
          
Instance:
<ex:productBag id="6026" inStock="232">
  <ex:name>Widget</ex:name>
  <ex:length>33</ex:length>
  <ex:shade>Light Blue</ex:shade>
</ex:productBag>
Instance:
<ex:productBag inStocck="332" id="6026">
  <ex:shade>Green</ex:shade>
  <ex:length>21</ex:length>
  <ex:name>Widget</ex:name>
</ex:productBag>

3.9 Optional Element

Definition
-
Examples
Example 15: OptionalMiddleName
<xs:element name="optionalMiddleName" type="ex:OptionalMiddleName"/>

<xs:complexType name="OptionalMiddleName">
  <xs:sequence>
    <xs:element name="firstName" type="xs:string"/>
    <xs:element name="middleName" type="xs:string" minOccurs="0"/>
    <xs:element name="lastName" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
Instance:
<ex:optionalMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:lastName>Downey</ex:lastName>
</ex:optionalMiddleName>
Instance:
<ex:optionalMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:middleName>Sumner</ex:middleName>
  <ex:lastName>Downey</ex:lastName>
</ex:optionalMiddleName>

3.10 Nillable Element

Definition
-
Examples
Example 16: NillableMiddleName
<xs:element name="nillableMiddleName" type="ex:NillableMiddleName"/>

<xs:complexType name="NillableMiddleName">
  <xs:sequence>
    <xs:element name="firstName" type="xs:string"/>
    <xs:element name="middleName" type="xs:string" nillable="true"/>
    <xs:element name="lastName" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
Instance:
<ex:nillableMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:middleName xsi:nil="true"/>
  <ex:lastName>Downey</ex:lastName>
</ex:nillableMiddleName>
Instance:
<ex:nillableMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:middleName>Sumner</ex:middleName>
  <ex:lastName>Downey</ex:lastName>
</ex:nillableMiddleName>

3.11 Nillable-Optional Element

Definition
-
Examples
Example 17: NillableOptionalMiddleName
<xs:element name="nillableOptionalMiddleName" type="ex:NillableOptionalMiddleName"/>

<xs:complexType name="NillableOptionalMiddleName">
  <xs:sequence>
    <xs:element name="firstName" type="xs:string"/>
    <xs:element name="middleName" type="xs:string" minOccurs="0" nillable="true"/>
    <xs:element name="lastName" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
Instance:
<ex:nillableOptionalMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:lastName>Downey</ex:lastName>
</ex:nillableOptionalMiddleName>
Instance:
<ex:nillableOptionalMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:middleName>Sumner</ex:middleName>
  <ex:lastName>Downey</ex:lastName>
</ex:nillableOptionalMiddleName>
Instance:
<ex:nillableOptionalMiddleName>
  <ex:firstName>Paul</ex:firstName>
  <ex:middleName xsi:nil="true"/>
  <ex:lastName>Downey</ex:lastName>
</ex:nillableOptionalMiddleName>

3.12 Simple List

Definition
-
Examples
Example 18: LanguageList
<xs:element name="languages" type="ns:Languages" />

<xs:simpleType name="xs:Languages">
  <xs:list itemType="xs:string"/>
</xs:simpleType>
Instance:
<languages>en_GB en_IN en_ZA en_US fr_FR fr_CA</languages>

3.13 Wrapped Repeated Element

Definition
-
Examples
Example 19: ItemList
<xs:element name="itemList" type="ex:ItemList"/>

<xs:complexType name="ItemList">
  <xs:sequence>
    <xs:element name="item" type="xs:string" minOccurs=0 maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>
Instance:
<ex:itemList>
    <ex:item>first thing</ex:item>
    <ex:item>second thing</ex:item>
    <ex:item>third thing</ex:item>
    <ex:item>fourth thing</ex:item>
</ex:itemList>

3.14 Repeated Element

Definition
-
Examples
Example 20: Contact
<xs:element name="contact" type="ex:Contact"/>

<xs:complexType name="Contact">
  <xs:sequence>
    <xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="addressLine" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="telephoneNumber" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>
          
Instance:
<ex:customer>
    <ex:name>Benn</ex:name>
    <ex:addressLine>52, Festive Road</ex:addressLine>
    <ex:telephoneNumber>+44 207 946 0001</ex:telephoneNumber>
</ex:customer>
Instance:
<ex:customer>
    <ex:name>Mr</ex:name>
    <ex:name>Benn</ex:name>
    <ex:addressLine>52, Festive Road</ex:addressLine>
    <ex:addressLine>London</ex:addressLine>
    <ex:addressLine>England</ex:addressLine>
    <ex:telephoneNumber>+44 207 946 0001</ex:telephoneNumber>
    <ex:telephoneNumber>+44 7700 900 001</ex:telephoneNumber>
</ex:customer>

4. References

4.1 Normative References

[XML Schema Part 1: Structures Second Edition]
XML Schema Part 1: Structures Second Edition, Henry S. Thompson, David Beech, Murray Maloney, and Noah Mendelsohn, Editors. World Wide Web Consortium, 28 Oct 2004. This version is http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/. The latest version is available at http://www.w3.org/TR/xmlschema-1/.
[XML Schema Part 2: Datatypes Second Edition]
XML Schema Part 2: Datatypes, Paul V. Biron and Ashok Malhotra, Editors. World Wide Web Consortium, 28 Oct 2004. This version is http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/. The latest version is available at http://www.w3.org/TR/xmlschema-2/.
[RFC 2119]
Key words for use in RFCs to Indicate Requirement Levels, S. Bradner, Editor. IETF, March 1997. (See http://www.ietf.org/rfc/rfc2119.txt.)
[WS-Security]
Web Services Security: SOAP Message Security 1.0 (WS-Security 2004), A. Nadalin, C. Kaler, P. Hallam-Baker, R. Monzillo, Editors. OASIS Standard, OASIS, March 2004. (See http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf.)

4.2 Informative References

[X.694]
Information technology - ASN.1 encoding rules: Mapping W3C XML schema definitions into ASN.1, International Telecommunications Union Recommendation. X.694 January 2004. (See http://www.itu.int/ITU-T/studygroups/com17/languages/X694.pdf.)
[Versioning-Use-Cases]
XML Schema Versioning Use Cases, Hoylen Sue, World Wide Web Consortum (XML Schema Working Group Discussion Document), 31 January 2006. (See http://www.w3.org/XML/2005/xsd-versioning-use-cases/2006-01-31.html.)

A. Acknowledgements (Non-Normative)

This document is the work of the W3C XML Schema Patterns for Databinding Working Group.

Members of the Working Group are (at the time of writing, and by alphabetical order): Paul V. Biron (Health Level Seven, Inc.), Jonathan Calladine (BT), George Cowe (Origo Services Limited), Paul Downey (BT), Otu Ekanem (BT), Paul Fremantle (WSO2), Anthony Julian (Health Level Seven, Inc.), Yves Lafon (W3C/ERCIM), Ajith Ranabahu (WSO2).

Previous members of the Working Group were: Sekhar Vajjhala (Sun Microsystems).

The people who have contributed to discussions on public-xsd-databinding@w3.org are also gratefully acknowledged.