<xsd:schema> Element 

Contains the definition of a 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): ''
  id = ID
  targetNamespace = anyURI
  version = token
  xml:lang = language
  {any attributes with non-schema Namespace}...>
Content: ((include | import | redefine | annotation)*, (((simpleType | 
complexType | group | attributeGroup) | element | attribute | notation), 
annotation*)*)
</schema>

Attributes

  • attributeFormDefault
    The form for attributes declared in the target namespace of this schema. The value must be one of the following strings: qualified or unqualified. The default is unqualified.

    If the value is unqualified, attributes from the target namespace are not required to be qualified with the namespace prefix.

    If the value is qualified, attributes from the target namespace must be qualified with the namespace prefix.

    This value is the global default for all attributes declared in the target namespace. Individual attributes can override this setting for their local scope using the form attribute.

    Optional.

  • blockDefault
    The type of derivation. The blockDefault attribute sets the default value of the block attribute on element and complexType elements in the target namespace of this schema. The block attribute prevents a complex type (or element) that has the specified type of derivation from being used in place of the inherited complex type (or element). This value can contain #all or a list that is a subset of extension, restriction, or substitution.

    extension

    Prevents complex types derived by extension from being used in place of this complex type.

    restriction

    Prevents complex types derived by restriction from being used in place of this complex type.

    substitution

    Prevents substitution of elements. (An element can declare itself a substitution for another element by specifying the name of the other element in its substitutionGroup attribute.)

    #all

    Prevents all derived complex types from being used in place of this complex type.

    Optional.

  • elementFormDefault
    The form for elements declared in the target namespace of this schema. The value must be one of the following strings: qualified or unqualified. The default is unqualified.

    If the value is unqualified, elements from the target namespace are not required to be qualified with the namespace prefix.

    If the value is qualified, elements from the target namespace must be qualified with the namespace prefix.

    This value is the global default for all elements declared in the target namespace. Individual elements can override this setting for their local scope using the form attribute.

    Optional.

  • finalDefault
    The type of derivation. The finalDefault attribute sets the default value of the final attribute on element, simpleType, and complexType elements in the target namespace of this schema. The final attribute prevents the specified type of derivation of an element, simpleType,or complexType element. For element and complexType elements, this value can contain #all or a list that is a subset of extension or restriction. For simpleType elements, this value can additionally contain list and union.

    extension

    By default, elements in this schema cannot be derived by extension. Applies to element and complexType elements only.

    restriction

    Prevents derivation by restriction.

    list

    Prevents derivation by list. Applies to simpleType elements only.

    union

    Prevents derivation by union. Applies to simpleType elements only.

    #all

    #all. By default, elements in this schema cannot be derived by any method.

    Optional.

  • id
    The ID of this element. The id value must be of type ID and be unique within the document containing this element.

    Optional.

  • targetNamespace
    The URI reference of the namespace of this schema. A prefix for the namespace can also be assigned. If no prefix is assigned, the schema components of the namespace can be used with unqualified references.

    Optional.

  • version
    The version of the schema.

    Optional.

  • xml:lang
    The indicator of the language used in the contents.

    Optional.

Element Information

Number of occurrences

One time

Parent elements

(No parent elements)

Content

include, import, annotation, redefine

attribute, attributeGroup, element, group, notation, simpleType, complexType

Other

The include, import, and redefine elements must come before the other elements — except for annotation element, which can appear anywhere.

Remarks

The schema element is the document element (the top-level element) in a schema definition.

The namespaces specified using the xmlns attribute must include the namespace for the schema-defining elements and attributes (schema, element, and so on). Any prefix can be used, but it is convenient to make the schema namespace the default namespace to avoid having to use a prefix on every XML Schema element.

The targetNamespace is the namespace of all schema components in this schema as well as any schemas included using the include element. (Included schemas must have the same target namespace as the containing schema or have no target namespace at all.) In the following example, the schema components (element name, type) in the http://www.w3.org/2001/XMLSchema namespace are unqualified and those for http://tempuri.org/myschema (mydecimal) are qualified with the msc prefix.

<xs:schema 
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:msc="http://tempuri.org/myschema"
     targetNamespace="http://tempuri.org/myschema">
  <xs:element name="Price" type="msc:mydecimal"/>
</xs:schema>

For XML Schema, the namespace is the following:

http://www.w3.org/2001/XMLSchema

In addition, the schema element should also contain namespace declarations for any other schemas that it uses.

Example

The following schema uses the XML Schema namespace as the default namespace and defines the target namespace for the schema as http://mynamespace/myschema.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         targetNamespace="http://mynamespace/myschema">
  <!--Put schema content here  -->
</xs:schema>

Other Resources

For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502\#element-all.

See Also

Reference

XML Schemas (XSD) Reference
XML Schema Elements
<xsd:include> Element