XML Schema: Constraints

Unlike DTDs, XML schemas enable you to specify constraints that define the valid values for elements and attributes. For example, the code snippet on the right restricts an EmpAge element to contain values between 0 and 100. In addition, you can specify regular expression values, such as [a-z], for elements and attributes.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="EmpAge">
    <xs:simpleType>

      <xs:restriction base="xs:integer">
        <xs:minInclusive value="0"/>
        <xs:maxInclusive value="100"/>
      </xs:restriction>

    </xs:simpleType>
  </xs:element>

// Additional declarations...
Click the Next button to continue.