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>

XML Schema Library

The Stylus Studio XML Schema Library provides a detailed reference of many of the world's most commonly used XML vocabularies in an easy-to-read format.

ZapThink Report: Using Stylus Studio to Deploy XML Data Services

A Zapthink analyst discusses how to create the next generation of XML data services using Stylus Studio XML tools - Download the special report today for free.

How to Build PDF Forms using Stylus Studio

Learn how to build PDF Forms using Stylus Studio and the RenderX XEP FO processor

Manufacturing

Manufacturing

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member