Understanding XML Schema (XSD)
Advertisement
Ad
What is XSD?
XML Schema Definition (XSD) defines the structure and rules an XML document must follow — which elements, types, and order are allowed. It validates that XML is correct.
A Simple Schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Valid Against the Schema
<person>
<name>Sara</name>
<age>25</age>
</person>
Common XSD Data Types
| Type | Example |
|---|---|
| xs:string | "hello" |
| xs:integer | 42 |
| xs:decimal | 3.14 |
| xs:date | 2026-01-01 |
| xs:boolean | true |
FAQs
XSD vs DTD?
XSD is newer, supports data types and namespaces; DTD is older and limited. More in our XML guides.
Why validate with a schema?
To guarantee data integrity before processing.
