Library tutorials & articles

XSD Schemas for VB Developers

Tighter Validation

In the example above, we defined the shipName field as xsd:string. In many cases, you’ll want to be more specific than that. For example, you might want to specify that the maximum length is 40 characters. To do this, you define a new type that inherits from the built-in string type and adds a restriction on the length. You do this using the <xsd:simpleType> element:

<xsd:simpleType name="shipNameType">
  <xsd:restriction base="xsd:string">
    <xsd:maxLength value="40"/>
  </xsd:restriction>
</xsd:simpleType>

Here, you use the <xsd:restriction> element to indicate that this simple type restricts the base type xsd:string. Then you use <xsd:maxLength> to indicate the maximum length of the string. There are other ways you can restrict values, for example you could use patterns to specify that a string must contain valid telephone number in the form (703) 606-1234:

<simpleType name="telType">
  <restriction base="string">
    <pattern value="\(\d{3}\) \d{3}-\d{4}"/>
  </restriction>
</simpleType>

You can also restrict the values of numbers by specifying valid ranges. For example, to restrict the Quantity between 1 and 100 you’d write:

<xsd:simpleType name="quantityType">
  <xsd:restriction base="xsd:short">
    <xsd:minInclusive value="1"/>
    <xsd:maxInclusive value="100"/>
  </xsd:restriction>
</xsd:simpleType>

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of XSD Schemas for VB Developers.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • Java Posse #202 - Newscast for Aug 22nd 2008

    Newcast for August 22nd, 2008Fully formatted shownotes can always be found at http://javaposse.com Sadly, Java does not run on the Mars LanderThe Golden Gate Project http://research.sun.com/projects/goldengate/Space surveillance radar http://www.sun.com/aboutsun/pr/2008-04/sunflash Google has r...

Related jobs