Jesper Tverskov, September 27, 2007

XML Schema Element Syntax Summary

The summaries are taken from the XML Schema Recommendations, made more user-friendly, and link back to the specs. All elements can have an "id" attribute and all elements can have xs:annotation as child except xs:annotation itself.

1. Schema, Import, Include, Redefine

1.1 xs:schema

<schema
  attributeFormDefault = (qualified | unqualified) : unqualified
  blockDefault = (#all | List of (extension | restriction | substitution))  : ''
  elementFormDefault = (qualified | unqualified) : unqualified
  finalDefault = (#all | List of (extension | restriction | list | union))  : ''
  targetNamespace = anyURI
  version = token
  xml:lang = language>
  Content: ((include | import | redefine)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation))*)
</schema>

1.2 xs:import

<import
  namespace = anyURI
  schemaLocation = anyURI />

1.3 xs:include

<include
  schemaLocation = anyURI/>

1.4 xs:redefine

<redefine
   schemaLocation = anyURI>
  Content: (simpleType | complexType | group | attributeGroup)*
</redefine>

2. Simple and complex

2.1 xs:complexType

<complexType
  abstract = boolean : false
  block = (#all | List of (extension | restriction))
  final = (#all | List of (extension | restriction))
  mixed = boolean : false
  name = NCName>
  Content: (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
</complexType>

2.2 xs:simpleType

<simpleType
  final = (#all | List of (list | union | restriction))
  name = NCName>
  Content: (restriction | list | union)
</simpleType>

2.3 xs:complexContent

<complexContent
  mixed = boolean>
  Content: (restriction | extension)
</complexContent>

2.4 xs:simpleContent

<simpleContent>
  Content: (restriction | extension)
</simpleContent>

3. Extension and Restriction

3.1 xs:extension - simpleContent

<extension
  base = QName>
  Content: ((attribute | attributeGroup)*, anyAttribute?)
</extension>

3.2 xs:extension - complexContent

<extension
  base = QName>
  Content: ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
</extension>

3.3 xs:restriction - simpleContent

<restriction
  base = QName>
  Content: (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?)
</restriction>

3.4 xs:restriction - complexContent

<restriction
  base = QName>
  Content: (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)
</restriction>

3.5 xs:restriction - simpleType

<restriction
  base = QName >
  Content: (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)
</restriction>

4. Element and attribute

4.1 xs:any

<any
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1
  namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  processContents = (lax | skip | strict) : strict/>

4.2 xs:element

<element
  abstract = boolean : false
  block = (#all | List of (extension | restriction | substitution))
  default = string
  final = (#all | List of (extension | restriction))
  fixed = string
  form = (qualified | unqualified)
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1
  name = NCName
  nillable = boolean : false
  ref = QName
  substitutionGroup = QName
  type = QName>
  Content: ((simpleType | complexType)?, (unique | key | keyref)*)
</element>

4.3 xs:group

<group
  maxOccurs = (nonNegativeInteger | unbounded) : 1
  minOccurs = nonNegativeInteger : 1
  name = NCName
  ref = QName>
  Content: (all | choice | sequence)?
</group>

4.4 xs:anyAttribute

<anyAttribute
  namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  processContents = (lax | skip | strict) : strict/>

4.5 xs:attribute

<attribute
  default = string
  fixed = string
  form = (qualified | unqualified)
  name = NCName
  ref = QName
  type = QName
  use = (optional | prohibited | required) : optional>
  Content: (simpleType?)
</attribute>

4.6 xs:attributeGroup

<attributeGroup
  name = NCName
  ref = QName>
  Content: ((attribute | attributeGroup)*, anyAttribute?)
</attributeGroup>

5. Model groups

5.1 xs:sequence

<sequence
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1>
  Content: (element | group | choice | sequence | any)*
</sequence>

5.2 xs:choice

<choice
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1>
  Content: (element | group | choice | sequence | any)*
</choice>

5.3 xs:all

<all
  maxOccurs = 1 : 1
  minOccurs = (0 | 1) : 1>
  Content: (element*)
</all>

6. List, Union, Notation

6.1 xs:list

<list
  itemType = QName>
  Content: (simpleType?)
</list>

6.2 xs:union

<union
  memberTypes = List of QName>
  Content: (simpleType*)
</union>

6.3 xs:notation

<notation
  name = NCName
  public = token
  system = anyURI/>

7. Documentation

7.1 xs:annotation

<annotation>
  Content: (appinfo | documentation)*
</annotation>

7.2 xs:documentation

<documentation
  source = anyURI
  xml:lang = language>
  Content: ({any})*
</documentation>

7.3 xs:appinfo

<appinfo
  source = anyURI>
  Content: ({any})*
</appinfo>

8. Unique and Key

8.1 xs:unique

<unique
  name = NCName>
  Content: (selector, field+)
</unique>

8.2 xs:key

<key
  name = NCName>
  Content: (selector, field+)
</key>

8.3 xs:keyref

<keyref
  name = NCName
  refer = QName>
  Content: (selector, field+)
</keyref>

8.4 xs:selector

<selector
   xpath = a subset of XPath expression/>

8.5 xs:field

<field
   xpath = a subset of XPath expression/>

9. Facets

All facets except Patern and Enumeration can have a "fixed" attribute (true/false). If "true" a derived type cannot change the value.

9.1 xs:length

<length
  value = nonNegativeInteger/>

9.2 xs:minLength

<minLength
   value = nonNegativeInteger/>

9.3 xs:maxLength

<maxLength
   value = nonNegativeInteger/>

9.4 xs:pattern

<pattern
   value = string/>

9.5 xs:enumeration

<enumeration
   value = anySimpleType/>

9.6 xs:whitespace

<whiteSpace
   value = (collapse | preserve | replace)/>

9.7 xs:maxInclusive

<maxInclusive
   value = anySimpleType/>

9.8 xs:maxExclusive

<maxExclusive
   value = anySimpleType/>

9.9 xs:minExclusive

<minExclusive
   value = anySimpleType/>

9.10 xs:minInclusive

<minInclusive
   value = anySimpleType/>

9.11 xs:totalDigits

<totalDigits
   value = positiveInteger/>

9.12 xs:fractionDigits

<fractionDigits
   value = nonNegativeInteger/>

Updated 2009-08-06