Editar

Compartilhar via


Simple Type Derivation Using the Restriction Mechanism

Overview

When you derive a new simple type from an existing simple type by using the restriction mechanism, you are typically restricting the values allowed in an instance message for that attribute or element value to a subset of those values allowed by the base simple type. For example, you can restrict a string type to be one of several enumerated strings.

For comprehensive information about deriving new simple types by using the restriction mechanism, refer to the W3C website. For various links to this and other websites, see XSD Resources on the Web.

Field Element and Field Attribute

To derive a simple type by using restriction, select the relevant Field Element node or Field Attribute node in the schema tree and then, in the Properties window, select a simple type from the drop-down list for the Base Data Type property. As soon as you have selected a value for this property, the Derived By property automatically changes from its default value to Restriction, which serves as the default value for type derivation. Also, a whole new category of properties, called Restriction, becomes available in the Properties window.

Depending on the base data type you select, different properties are available to be set in this new category. For example, if the base data type is numeric, the properties MaxFacet Type (when MaxFacet Value is set), MaxFacet Value, MinFacet Type (when MinFacet Value is set), and MinFacet Value are available for defining an inclusive or exclusive range of allowed values. If the base data type is a string type, the Length, Maximum Length, and Minimum Length properties are available for constraining the length of the string.

For more information about the various restriction properties of field nodes, see the Field Element Node Properties in the UI guidance and developers API namespace reference.

When you first change a Field Element node or Field Attribute node from having a data type to having a base data type (thereby starting the process of simple type derivation), leave the Derived By property set to Restriction, and provide an enumeration-based restriction to the allowed string values, you can observe the following changes in the corresponding fragment in the XSD view:

  • Before, with a newly inserted Field Element node named WestCoastStates.

    <xs:element name="ContainingRecord">  
        <xs:complexType>  
            <xs:sequence>  
                <xs:element name="WestCoastStates" type="xs:string" />  
            </xs:sequence>  
        </xs:complexType>  
    </xs:element>  
    
  • After setting the Base Data Type property to "xs:string", and leaving the derivation default of Restriction for the Derived By property.

    <xs:element name="ContainingRecord">  
        <xs:complexType>  
            <xs:sequence>  
                <xs:element name="WestCoastStates" >  
                    <xs:simpleType>  
                        <xs:restriction base="xs:string" />  
                    </xs:simpleType>  
                </xs:element>  
            </xs:sequence>  
        </xs:complexType>  
    </xs:element>  
    
  • After setting the Enumeration property in the Restriction category to the names of the three states on the west coast of the continental United States.

    <xs:element name="ContainingRecord">  
        <xs:complexType>  
            <xs:sequence>  
                <xs:element name="WestCoastStates">  
                    <xs:simpleType>  
                        <xs:restriction base="xs:string" />  
                            <xs:enumeration value="Washington" />  
                            <xs:enumeration value="Oregon" />  
                            <xs:enumeration value="California" />  
                        </xs:restriction>  
                    </xs:simpleType>  
                </xs:element>  
            </xs:sequence>  
        </xs:complexType>  
    </xs:element>  
    

See Also

Simple Type Derivation