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>

DB2

IBM DB2 is a database management system for powering business applications. Learn how to build XML solutions on DB2 using Stylus Studio's DB2 tools.

Report Generation - Visually Defining Relationships in XML Publisher

Develop report generation applications with a powerful relationship manager in XML Publisher which provides a powerful and easy way to group and join data from one or more data sources.

Apache FOP

Apache FOP is an open-source engine is available from the Apache project that renders XSL-FO into PDF and other popular document formats. Apache FOP is fully integrated with Stylus Studio's XSL:FO tools.

XML Programming

Simplify XML Programming with Stylus Studio's XML Pipeline, a powerful tool for modeling, programming, debugging and deploying complete XML programs.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member