Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

XML Schema Reference by sus16053

VIEWS: 6 PAGES: 14

									XML Schema Reference
Internet Explorer 5 includes support for XML Schema.

The W3C XML Activity Page states: "While XML 1.0 supplies a mechanism, the Document Type Definition (DTD) for declaring constraints on the use of
markup, automated processing of XML documents requires more rigorous and comprehensive facilities in this area. Requirements are for
constraints on how the component parts of an application fit together, the document structure, attributes, datatyping, and so on. The W3C XML


Schema Working Group is addressing means for defining the structure, content and semantics of XML documents."
The XML Schema language is based on the XML-Data note submitted to the W3C. XML Schema as implemented in this release can be thought of as the
subset of the XML-Data submission that corresponds to the feature set proposed for Document Content Description (DCD) .
Microsoft is providing this release of XML Schema with data type support that might be useful for developers interested in building prototypes and
gaining experience with schema and rich data types. Microsoft is actively involved in defining the emerging W3C XML schema standard and will track
this effort. Developers should note that this version of XML Schema is subject to change.
Unlike the unique DTD syntax, XML Schema allows you to define the rules governing the relations between elements and attributes using a standard
XML instance syntax, which can be parsed and managed using XML applications. XML Schema also adds support for namespaces, data types, and
such useful features as range constraints.

The definitions in an XML schema are contained within the top-level Schema document element. The Schema document element definition must
come from the namespace: xmlns="urn:schemas-microsoft-com:xml-data." The namespace declaration is an XML processing instruction (PI) as
defined in the W3C XML Namespace Working Draft . It is convenient to make the Schema namespace the default namespace to avoid having to prefix
all definitions within a schema. This documentation uses the convention that the schema namespace is the default namespace, and omits a prefix
from all XML Schema element and attribute names.
The Schema document element in an XML Schema document should also contain namespace declarations for any other schemas, such as the
namespace that defines the built-in data types for XML Schema.
<Schema name="myschema" xmlns="urn:schemas-microsoft-com:xml-data"
                                              xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <!-- ... -->
</Schema>
The Schema document element can contain any number of top-level declarations. The principal XML Schema elements include ElementType (which
declares element types) and AttributeType (which declares attribute types). These elements must have an explicit name attribute that is unique
within the schema. The element and attribute elements can appear within the ElementType element to constrain the content and attributes that can
appear in elements of the named type. The ElementType attribute order and the group element allow you to further establish fine-grained
definitions. The minOccurs and maxOccurs attributes allow you to define the number of occurrences of an element or group.
The content for an element of a given element type can be defined as one of four categories: empty (no content), text only, subelements only, or a
mix of text and subelements. This choice is expressed in the ElementType attribute named content, which can take the values "empty," "textOnly,"
"eltOnly," and "mixed," respectively.
Element types and attribute types can constrain their values and contents to be instances of a particular data type, referenced from the datatype
element namespace. To use the datatype namespace in a schema, it must be declared within the Schema element. The dt:type attribute can then
be used to reference data types; in the Internet Explorer 5 implementation, element and attribute types can take "rich" data types. For a complete
description of data types, see XML Data Types Reference.
Finally, note that in XML, schema files are optional and are not required. Some XML applications do not require validation and do not specify a
schema file. For a detailed description and examples of these elements, see the reference topic for each XML Schema element.

XML Schema Elements
The following table describes the XML Schema elements.
attribute          Refers to a declared attribute type that can appear within the scope of the named ElementType element.
AttributeType      Defines an attribute type for use within the Schema element.
datatype           Specifies the data type for the ElementType or AttributeType element.
description        Provides documentation about an ElementType or AttributeType element.
element            Refers to a declared element type that can appear within the scope of the named ElementType element.
ElementType        Defines an element type for use within the Schema element.
group              Organizes content into a group to specify a sequence.
Schema             Identifies the start of a schema definition.

XML Data Types Support
Support for data types is integrated into this release. For more information, see XML Data Types Reference.
See Also
             XML Schema Developer's Guide
             XML DOM Reference
attribute Element
Refers to a declared attribute type that can appear within the scope of the named ElementType element.
Syntax
      <attribute
           default="default-value"
           type="attribute-type"
           [required="{yes | no}"] >
Attributes

     default
            Default value for the attribute. This specified default takes precedence over any
            default provided on the AttributeType element it refers to.

     type
            Name of an AttributeType element defined in this schema (or another schema
            indicated by the specified namespace). The supplied value must correspond to the
            name attribute on the AttributeType element. Note that the type can include a
            namespace prefix.

     required
            Indicator of whether the attribute must be present on the element. Optional if the
            required attribute is present on the referenced AttributeType.
Element Information
    Number of
                      Number of attribute types specified in the schema.
   occurrences
 Parent elements ElementType
  Child elements (No child elements)
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

     When the required attribute is set to "yes" and the default attribute specifies a default
     value, the supplied default value must always be the value, and documents containing
     other attribute values are invalid.
     When the required attribute is set to "yes" and no default is specified, each element
     whose type is declared to have the attribute must supply its value.
AttributeType Element
Defines an attribute type for use within the Schema element.
Syntax
      <AttributeType
           default="default-value"
           dt:type="primitive-type"
           dt:values="enumerated-values"
           name="idref"
           required="{yes | no}" >
Attributes

     default
            Default value for the attribute. The default value must be legal for that attribute
            instance. For example, when the attribute is an enumerated type, the default value
            must appear in the values list.

     dt:type
            Specifies the data type for this attribute type. In the implementation provided with
            Internet Explorer 5, an attribute can take one of the following types: entity, entities,
            enumeration, id, idref, idrefs, nmtoken, nmtokens, notation, or string. When the type
            "enumeration" is selected, the dt:values attribute should also be supplied, listing the
            allowed values. For more information about data types, see XML Data Types.

     dt:values
            When dt:type is set to "enumeration," this attribute lists the possible values.

     name
            Name of the attribute type. This attribute is required. References to this attribute type
            within an ElementType definition are made in the schema with the attribute element.
            The name supplied here corresponds to the "type" attribute of the "attribute" element.

     required
            Indicator of whether the attribute must be present on the element.
Element Information
    Number of
                      Unlimited
   occurrences
 Parent elements ElementType, Schema
  Child elements datatype, description
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

     An AttributeType declaration contained within an ElementType element defines that
     attribute type within the scope of the ElementType that contains it.
     In XML Schema, as in XML 1.0, the order of appearance of attributes in an element is
     not constrained, and a given attribute can appear no more than once in an element.
Example

    The following example shows an enumeration and its document type definition (DTD)
    equivalent.
    <AttributeType name="colors" dt:type="enumeration"
       dt:values="red green blue">
    <!ATTLIST x colors (red | green | blue)>
    The following example declares an attribute type called "myattr." This declaration
    constrains "myattr" attributes to contain only a name token.
    <AttributeType name="myattr" dt:type="nmtoken"/>
datatype Element
Specifies the data type for the ElementType or AttributeType element.
Syntax
      <datatype
           dt:type="datatype">
Attributes

     dt:type
            Data type. For a list of valid values, see XML Data Types Preview.
           <ElementType name="colors">
                <datatype dt:type="char"/>
           </ElementType>
Element Information
    Number of
                     1
   occurrences
 Parent elements AttributeType, ElementType
  Child elements (No child elements)
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag        well-formed.
Remarks

     The datatype functionality is an extension offered by XML Schema that cannot be
     specified using the document type definition (DTD) syntax.
description Element
Provides documentation about an ElementType or AttributeType element.
Syntax
     <description>
Element Information
    Number of
                    1
   occurrences
 Parent elements AttributeType, ElementType, Schema, group, element, attribute
  Child elements Any well-formed XML content
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag       well-formed.
Remarks

     Information supplied within the description element is not used in validation, but
     provides a standardized way to supply information that can be retrieved by tools.
Example
    <ElementType name="Book">
        <description>
        This is how we describe the books we sell.                                        Be sure to specify
           ageGroup!
        </description>
        <element type="ageGroup">
          <default>ADULT</default>
        </element>
    </ElementType>
element Element
Refers to a declared element type that can appear within the scope of the named ElementType element.
Syntax
      <element
           type="element-type"
           [minOccurs="{0 | 1}"]
           [maxOccurs="{1 | *}"]
      >
Attributes

     type
            Name of an ElementType element defined in this schema (or another schema
            indicated by the specified namespace). The supplied value must correspond to the
            name attribute on the ElementType element. Note that the type can include a
            namespace prefix.

     minOccurs
            Optional. Minimum number of times the reference element type can occur on the
            element. The following values can be assigned to this attribute.
0 When the minimum value is zero, the specified element is not required; the element is optional.
1 The specified element must occur at least once.

     maxOccurs
            Optional. Maximum number of times the element can occur on the element. The
            following values can be assigned to this attribute.
1 Can occur at most once.
* Unlimited number of occurrences.
Element Information
    Number of
                      Number of element types defined in the schema.
   occurrences
 Parent elements ElementType, group
  Child elements (No child elements)
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

     ElementType declarations can constrain the content and attributes that appear in
     elements of the named type by referring to other element type or attribute type
     declarations.
     The minOccurs and maxOccurs attributes have the default value "1." An element with
     neither attribute specified uses these default values and therefore must appear once and
     only once in a content model.
ElementType Element
Defines an element type for use within the Schema element.
Syntax
      <ElementType
           content="{empty | textOnly | eltOnly | mixed}"
           dt:type="datatype"
           model="{open | closed}"
           name="idref"
           order="{one | seq | many}" >
Attributes

     content
             Indicator of whether the content must be empty, or can contain text, elements, or
             both. The following values can be assigned to this attribute. Default is "mixed".
empty The element cannot contain content.
           The element can contain only text, not elements. Note that if the model attribute is set to "open," the element can contain text and other
textOnly
           unnamed elements.
eltOnly The element can contain only the specified elements. It cannot contain any free text.
mixed The element can contain a mix of named elements and text. Default.
        <ElementType name="x" content="empty"/>
        <ElementType name="x" content="textOnly"/>
        <ElementType name="x" content="eltOnly">
               <element type="y">
        </ElementType>
        <ElementType name="x" content="mixed">
               <element type="q">
               <element type="r">
        </ElementType>
             The document type definition (DTD) equivalent is as follows:
             empty: <!ELEMENT x EMPTY>
             textOnly: <!ELEMENT x (#PCDATA)>
             eltOnly: <!ELEMENT x y>
             mixed: <!ELEMENT x (#PCDATA | q | r)*>
     dt:type
             Data type of the element. The valid data types are defined in the XML Data Types
             Preview.

     model
             Indicator of whether the content can include only what is defined in the content
             model, or can contain content not specified in the model. Default is "open".
             <ElementType name="x" model="open"/>
             When the model is defined as open, the element can include additional elements or
             attributes not declared explicitly in the content model. These additional tags can come
             from the same namespace or from a different namespace. If they are in the same
             namespace, there must be a corresponding ElementType or AttributeType definition
             in the schema.
            When the model is defined as closed, the element cannot include elements and cannot
            include mixed content not specified in the content model. The document type
            definition (DTD) uses a closed model.

       name
            Name of the element. This attribute is required. If this element type is declared as a
            valid child of another element type, this name is specified within an element element.
            <ElementType name="x">
            </ElementType>
            The DTD equivalent is as follows:
            <!ELEMENT x EMPTY>
       order
            The following values can be assigned to this attribute.
one       Permits only one of a set of elements.
seq       Requires the elements to appear in the specified sequence.
many      Permits the elements to appear (or not appear) in any order. Default.

            The "seq" setting is needed to specify valid sequences. For example, it can be used to
            specify when a particular sequence such as "x1,y1" or "x2,y2" is valid but no other
            possible combinations are valid. The "seq" value serves the same role as parentheses
            in a DTD. Default is "many".
            The following example demonstrates the "one" setting:
            <ElementType name="z" order="one">
            <element type="x">
            <element type="y">
            </ElementType>
            The following example demonstrates the "seq" setting:
            <ElementType name="x" order="one">
              <group order="seq">
                <element type="x1">
                <element type="y1">
              </group>
              <group order="seq">
                <element type="x2">
                <element type="y2">
              </group>
            </ElementType>
            The following example demonstrates the "many" setting:
           <ElementType name="x" content="eltOnly" order="many">
                  <element type="q">
                  <element type="r">
           </ElementType>
Element Information
       Number of
                      Unlimited
      occurrences
 Parent elements Schema
  Child elements Attribute, AttributeType, datatype, description, element, group
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

    The term "element type" refers to the element type of which all elements sharing a name
    are instances. Element types are declared in schemas; elements occur in documents.
    Element types are declared with the ElementType element type.
Example
    <ElementType name="x">
        <!-- element content declarations go here -->
    </ElementType>
group Element
Organizes content into a group to specify a sequence.
Syntax
      <group
           maxOccurs="{1 | *}"
           minOccurs="{0 | 1}"
           order="{one | seq | many}" >
Attributes

     maxOccurs
            Maximum number of times the group can occur. The following values can be
            assigned to this attribute.
1 Occurs at most once.
* Unlimited number of occurrences.

     minOccurs
            Minimum number of times the group can occur. The following values can be assigned
            to this attribute.
0 Not required; the group is optional.
1 Must occur at least once.

     order
            Constraints on the sequence of elements (and other contained groups) within this
            group. The following values can be assigned to this attribute.
one Permits only one instance of each element contained in the group. (This corresponds to the '|' symbol in the document type definition (DTD).)
seq Requires the elements in the group to appear in the specified sequence.
many Permits the elements in the group to appear (or not appear) in any order.

            The "seq" setting is needed to specify valid sequences. For example, it can be used to
            specify when a particular sequence such as "x1,y1" or "x2,y2" is valid but no other
            possible combinations are valid. The "seq" value serves the same role as parentheses
            in a DTD.
Element Information
    Number of
                      Unlimited
   occurrences
 Parent elements ElementType
  Child elements Element, description
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

     The order attribute takes the same values as the order attribute of the ElementType
     element.
     The minOccurs and maxOccurs attributes have the default value "1." A group with
     neither attribute must appear once and only once in a content model.
Examples
The following example demonstrates the "one" setting:
<ElementType name="z" order="one">
<element type="x">
<element type="y">
</ElementType>
The following represents a legal instance of the schema:
<z>
  <x/>
  <y></y>
</z>
The following example demonstrates the "seq" setting:
<ElementType name="x" order="one">
  <group order="seq">
    <element type="x1">
    <element type="y1">
  </group>
  <group order="seq">
    <element type="x2">
    <element type="y2">
  </group>
</ElementType>
The following two examples represent legal instances of this schema:
<x>
   <x1/>
   <y1/>
</x>

and:

<x>
   <x2/>
   <y2/>
</x>
The following example demonstrates the "many" setting:
<ElementType name="x" content="eltOnly" order="many">
    <element type='q'>
    <element type='r'>
</ElementType>
The following five examples represent all legal instances for this schema:
<x> </x>

<x> <q> </x>

<x> <r> </x>

<x> <q> <r> </x>

<x> <r> <q> </x>
Schema Element
Identifies the start of a schema definition.
Syntax
      <Schema
           name="schema-name"
           xmlns="namespace" >
Attributes

      name
            Name of the schema.

      xmlns
            One or more namespaces for use with the schema.
Element Information
     Number of
                      1
   occurrences
 Parent elements (No parent elements)
  Child elements AttributeType, ElementType, description
 Requires closing Yes. XML Schema is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of
          tag         well-formed.
Remarks

      The Schema element is the document element (the highest-level element) in a schema
      definition.
      The namespaces specified using the xmlns attribute must include the namespace for the
      schema-defining elements (Schema, ElementType, 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 Schema document element in an XML Schema should also contain namespace
      declarations for any other schemas, such as the namespace that defines the built-in data
      types for XML Schema.
Example
    <Schema name="fooSchema" xmlns="urn:schemas-microsoft-com:xml-data"
                             xmlns:dt="urn:schemas-microsoft-
    com:datatypes">

      </Schema>

								
To top