© 2004 Microsoft Corporation. All rights reserved.
Figure 1 Built-in Types
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://example.org/employee/"
  targetNamespace="http://example.org/employee/">
  <xsd:complexType name="EmployeeType">
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
      <xsd:element name="hiredate" type="xsd:date"/>
      <xsd:element name="salary" type="xsd:double"/>        
    </xsd:sequence> 
    <xsd:attribute name="id" type="xsd:string"/>
  </xsd:complexType> 
  <xsd:element name="employee" type="tns:EmployeeType"/>
</xsd:schema>
Figure 3 Simple Type Derivation Techniques

Derivation Element
Description
xsd:restriction
The new type created will be a restriction of the existing type, which means it will have a narrower set of legal values.
xsd:list
The new type created will be a whitespace-delimited list of another simple type.
xsd:union
The new type created will be a union of two or more other simple types.
Figure 4 Type Facets

Facet Element
What It Specifies
xsd:enumeration
A fixed value that the type must match
xsd:fractionDigits
The maximum number of decimal digits to the right of the decimal point
xsd:length
The number of characters in a string-based type, the number of octets in a binary-based type, or the number of items in a list-based type
xsd:maxExclusive
The exclusive upper-bound on the value space of the type
xsd:maxInclusive
The inclusive upper-bound on the value space of the type
xsd:maxLength
The maximum number of characters in a string-based type, the maximum number of octets in a binary-based type, or the maximum number of items in a list-based type
xsd:minExclusive
The exclusive lower-bound on the value space of the type
xsd:minInclusive
The inclusive lower-bound on the value space of the type
xsd:minLength
The minimum number of characters in a string-based type, the minimum number of octets in a binary-based type, or the minimum number of items in a list-based type
xsd:pattern
A pattern, based on a regular expression, that the type must match
xsd:totalDigits
The maximum number of decimal digits for types derived from number
xsd:whiteSpace
Rules for whitespace normalization
Figure 5 New Simple Types
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://example.org/ages/"
  targetNamespace="http://example.org/ages/">

  <xsd:simpleType name="age">
    <xsd:restriction base="xsd:unsignedByte">
      <xsd:minInclusive value="0"/>
      <xsd:maxInclusive value="122"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="recordAge">
    <xsd:restriction base="tns:age">
      <xsd:minInclusive value="101"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="normalAge">
    <xsd:restriction base="tns:age">
      <xsd:maxInclusive value="100"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="adultAge">
    <xsd:restriction base="tns:normalAge">
      <xsd:minInclusive value="18"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="teenAge">
    <xsd:restriction base="tns:normalAge">
      <xsd:minInclusive value="13"/>
      <xsd:maxInclusive value="19"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="infantAge">
    <xsd:restriction base="tns:normalAge">
      <xsd:maxInclusive value="3"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>
Figure 8 Complete Schema
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://example.org/employee/"
  targetNamespace="http://example.org/employee/">

  <xsd:simpleType name="genderIdentifiers">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="male"/>
      <xsd:enumeration value="female"/>
    </xsd:restriction>
  </xsd:simpleType>  

  <xsd:simpleType name="socialSecurityNumber">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{3}\-\d{2}\-\d{4}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="ageUnits">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="days"/>
      <xsd:enumeration value="weeks"/>
      <xsd:enumeration value="months"/>
      <xsd:enumeration value="years"/>
    </xsd:restriction>
  </xsd:simpleType>  

  <!-- extends a simple type into a complex type
       by adding the units attribute -->
  <xsd:complexType name="annotatedAge">
    <xsd:simpleContent>
      <xsd:extension base="xsd:unsignedShort">
        <xsd:attribute name="unit" use="required" 
                       type="tns:ageUnits"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:complexType name="Person">
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
      <xsd:element name="sex" type="tns:genderIdentifiers"/>
      <xsd:element name="age" type="tns:annotatedAge"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- extends a complex type by adding 
       two new elements -->
  <xsd:complexType name="Employee">
    <xsd:complexContent>
      <xsd:extension base="tns:Person">
        <xsd:sequence>
          <xsd:element name="ssnum" 
                       type="tns:socialSecurityNumber"/>
          <xsd:element name="salary" type="xsd:double"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:element name="employee" type="tns:Employee"/>
</xsd:schema>
Figure 9 Parts of the Complete Schema
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://example.org/employee/"
  targetNamespace="http://example.org/employee/">

  <xsd:simpleType name="genderIdentifiers">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="male"/>
      <xsd:enumeration value="female"/>
    </xsd:restriction>
  </xsd:simpleType>  

  <xsd:simpleType name="socialSecurityNumber">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{3}\-\d{2}\-\d{4}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="ageUnits">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="days"/>
      <xsd:enumeration value="weeks"/>
      <xsd:enumeration value="months"/>
      <xsd:enumeration value="years"/>
    </xsd:restriction>
  </xsd:simpleType>  

  <!-- extends a simple type into a complex type
       by adding the units attribute -->
  <xsd:complexType name="annotatedAge">
    <xsd:simpleContent>
      <xsd:extension base="xsd:unsignedShort">
        <xsd:attribute name="unit" use="required" 
                       type="tns:ageUnits"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
•••

MSDN Magazine Blog

MSDN Magazine Right Rail

14 Top Features of Visual Basic 14: The Q&A
Leading off the feature in the January issue of MSDN Magazine is Lucian Wischik’s fantastic look at Visual Basic .NET 14. As Wischik writes, the newes... More...
Wednesday, Jan 7
Big Start to the New Year at MSDN Magazine
Folks, things are hopping over here at MSDN Magazine. We are kicking off the new year with a pair of issues: Our regularly scheduled January issue and... More...
Friday, Jan 2

More MSDN Magazine Blog entries >


Receive the MSDN Flash e-mail newsletter every other week, with news and information personalized to your interests and areas of focus.