Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to XML
Understanding XML Schema (XSD)

Understanding XML Schema (XSD)

XML2,504 viewsBy Admin
xmlunderstandingschema

Advertisement

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

TypeExample
xs:string"hello"
xs:integer42
xs:decimal3.14
xs:date2026-01-01
xs:booleantrue

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.

Advertisement