ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

XML Tutorial• 7 min read

XML Schema Definition (XSD)

Modern W3C schema standard: Data types, restrictions, and complexType

XML Schema (XSD) is the modern XML-based successor to DTD, providing rich support for data types (integers, dates, booleans), custom regex patterns, and range restrictions.

Why XSD Surpassed DTD

XSD is itself written in XML, so you can parse and manipulate schemas using standard XML tools.

Support for data types: xs:string, xs:decimal, xs:integer, xs:boolean, xs:date.

xs:simpleType: Used for elements containing text only, allowing regex facets and value ranges.

xs:complexType: Used for elements containing child elements or attributes.

Customer XSD Schema Definition
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="customer">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="username" type="xs:string"/>
        <xs:element name="age">
          <xs:simpleType>
            <xs:restriction base="xs:integer">
              <xs:minInclusive value="18"/>
              <xs:maxInclusive value="120"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
        <xs:element name="email" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
Restricts age strictly to an integer between 18 and 120.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What is a major advantage of XML Schema (XSD) over legacy DTDs?