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"/>

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}"/>

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"/>

You might also like...


About the author

Yasser Shohoud United States

Yasser started programming at the age of 12 when he wrote his first text-based game on a Commodore PET. He's since moved to IBM mainframes then to Microsoft technologies and has worked as System...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius