XML SchemaElement


XML Schema 参考手册Complete XML Schema Reference

Definition and Usage

The schema element defines the root element of a schema.

Element Information

  • Parent Element:(None)

Syntax

<schema
id=ID
attributeFormDefault=qualified|unqualified
elementFormDefault=qualified|unqualified
blockDefault=(#all|list of (extension|restriction|substitution))
finalDefault=(#all|list of (extension|restriction|list|union))
targetNamespace=anyURI
version=token
xmlns=anyURI
any attributes
>

((include|import|redefine|annotation)*,(((simpleType|complexType|
group|attributeGroup)|element|attribute|notation),annotation*)*)

</schema>

Attributes Description
id Optional. Specifies a unique ID for the element.
attributeFormDefault

Optional. The form of attributes declared in the target namespace of the schema. The value must be one of the following strings: "qualified" or "unqualified". Default is "unqualified".

  • "unqualified" indicates that attributes in the target namespace do not need to be qualified by a namespace prefix.
  • "qualified" indicates that attributes in the target namespace must be qualified by a namespace prefix.
elementFormDefault

Optional. The form of elements declared in the target namespace of the schema. The value must be one of the following strings: "qualified" or "unqualified". Default is "unqualified".

  • "unqualified" indicates that elements in the target namespace do not need to be qualified by a namespace prefix.
  • "qualified" indicates that elements in the target namespace must be qualified by a namespace prefix.
blockDefault

Optional. Specifies the default value for the block attribute on element and complexType elements in the target namespace. The block attribute prevents complex types (or elements) with a specified derivation type from being used in place of the inherited complex type (or element). The value may 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 element substitution.
  • #all - Prevents all derived complex types from being used in place of this complex type.
finalDefault

Optional. Specifies the default value for the final attribute on element, simpleType, and complexType elements in the target namespace of the schema. The final attribute prevents the specified derivation type for element, simpleType, or complexType elements. For element and complexType elements, the value may contain #all or a list that is a subset of extension or restriction. For simpleType elements, the value may also contain list and union:

  • extension - By default, elements in this schema cannot be derived by extension. Applies only to element and complexType elements.
  • restriction - Prevents derivation by restriction.
  • list - Prevents derivation by list. Applies only to simpleType elements.
  • union - Prevents derivation by union. Applies only to simpleType elements.
  • #all - By default, elements in this schema cannot be derived by any method.
targetNamespace

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

version

Optional. Specifies the version of the schema.

xmlns

Specifies one or more URI references for namespaces used in this schema. If no prefix is assigned, the schema components of this namespace can be used with unqualified references.

any attributes

Optional. Specifies any other attributes with non-schema namespaces.

Example 1

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="values" type="xs:string">

</xs:schema>

Example 2

In this example, the schema components (element name, type) in the http://www.w3.org/2001/XMLSchema namespace are unqualified, while http://www.w3school.com.cn/w3schoolschema (mystring) is qualified by the wsc prefix:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsc="http://www.w3cschool.cc/w3shoolsschema">

<element name="fname" type="wsc:mystring"/>

</schema>


XML Schema 参考手册Complete XML Schema Reference Other Extensions