What is XML Schema (XSD)?

Estimated study time: 16 minutes.

XML Schema (XSD) is a more powerful, modern alternative to DTD for defining the structure and data types allowed in an XML document. Like a DTD, it's used to validate documents, but it adds proper data typing, namespace support, and is itself written in XML.

A Simple XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="course">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="xs:string"/>
        <xs:element name="duration" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Referencing the Schema

<course xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="course.xsd">
  <title>Data Analytics</title>
  <duration>4 Months</duration>
</course>

Why XSD Over DTD?

  • Supports real data types — strings, integers, dates, booleans — not just text.
  • Written in XML itself, so no separate syntax to learn.
  • Fully namespace-aware, unlike DTD.
  • Supports richer constraints like value ranges, patterns, and custom types.
💡 Tip: For any new project needing strict data validation, prefer XSD over DTD — DTD is mostly relevant now for maintaining legacy systems.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with the Data Analytics Course at Uncodemy.

Explore XML Course →