Examples of simpleTypes in an XML Schema

The W3C XML Schema Part 0: Primer specifies the following simpleType in its sample purchase order schema:

<!-- Stock Keeping Unit, a code for identifying products -->
               
<xsd:simpleType name="SKU"> 
               

              
<xsd:restriction base="xsd:string"> 
                   
<xsd:pattern value="\d{3}-[A-Z]{2}"/> 
                   
</xsd:restriction> 
                   

                
</xsd:simpleType>

This specifies that SKU is a simpleType. It is restricted to the values of the base type, which is xsd:string. This means that for a node that is of type SKU, the possible values are a subset of the values allowed for the xsd:string type.

The xsd:pattern element specifies that the pattern facet is being applied to the set of values allowed by the xsd:string type. The value of the xsd:pattern element is an XML Schema regular expression that specifies the allowable values for nodes of type SKU. In this example, the regular expression specifies that the value must be three digits, followed by a hyphen, followed by two uppercase ASCII letters - <xsd:pattern value="\d{3}-[A-Z]{2}"/>. For information about XML Schema expressions, see the W3C XML Schema Part 0: Primer.

Elsewhere in the purchase order schema, an attribute definition specifies that SKU is the type of its value:

<xsd:attribute name="partNum" type="SKU" use="required"/>
               

            

An XML document that uses a schema that contains this simpleType definition can specify the partNum attribute. The parser ensures that the value of the partNum attribute is in the range specified by the xsd:pattern element. The SKU type itself is not mentioned in the instance document.

Following is another example of a simpleType definition from the W3C XML Schema Part 0: Primer. This simpleType, myInteger, is based on the xsd:integer type. It specifies two facets ( minInclusive and maxInclusive), which specify the lower and upper inclusive bounds of the range of valid values.

<xsd:simpleType name="myInteger">
               

              
  <xsd:restriction base="xsd:integer">
                   
    <xsd:minInclusive value="10000"/>
                   
    <xsd:maxInclusive value="99999"/>
                   
  </xsd:restriction>
                   

                
</xsd:simpleType>

EII - Enterprise Information Integration

Learn how to build EII applications with Stylus Studio's powerful Enterprise Information Integration Tools.

XML Schema Quality Checker

Use IBM's alphaWorks XML Schema Quality Checker to check the quality and style of your XML schema documents. Fully integrated with the Stylus Studio XML Schema Editor and XML validator.

Accessing Relational Databases as XML with Stylus Studio's File Explorer

This demonstration is the first part of our series on working with relational and XML data, covering how to use Stylus Studio's File Explorer to connect to and query relational database tables as XML.

OASIS Catalog Support

Stylus Studio's features for working with OASIS catalogs allow you to incorporate any vendor's catalog - or one of your own - in your XML, making writing correct and robust XML easier than ever.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member