XSD: DataTypes and Validations
Types
There are lots of types built right into XSDs. You can also create your own type by adding restrictions to an existing type:
In the documentation, the following example is given:
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="10000"/>
<xsd:maxInclusive value="99999"/>
</xsd:restriction>
</xsd:simpleType>
You have a restriction which in this case is composed of two facets (minInclusive and maxInclusive). A list of facets is provided.
You might also want to try an enumeration (thanks Ron!) where a value should be one of a constrained number of possibilities:
<xsd:simpleType name="statetype">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AL"/>
<xsd:enumeration value="AK"/>
<xsd:enumeration value="AS"/>
<xsd:enumeration value="AZ"/>
<xsd:enumeration value="AR"/>
<xsd:enumeration value="CA"/>
<xsd:enumeration value="GRACE"/>
<xsd:enumeration value="CO"/>
<xsd:enumeration value="CT"/>
...
<xsd:enumeration value="WY"/>
</xsd:restriction>
</xsd:simpleType>
There is even a whole Regex style pattern language allowing statements like (thanks again Ron):
<xsd:simpleType name="zipformat">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{5}"/>
</xsd:restriction>
</xsd:simpleType>
There are lots of other capabilities including support for lists (whitespace delimited) and a number of trickier combinations, but I'm hoping these intro articles will help you to get started with Schemas (writing them has certainly helped me!).
Again, core references:
- XML Schema Part 0: Primer Second Edition
- XML Schema Part 1: Structures Second Edition
- XML Schema Part 2: Datatypes Second Edition
They're actually more readable than you'd expect!
Thoughts?


There are no comments for this entry.
[Add Comment]