Skip to content
\n","url":"https://ez4code.com/snippets/xml-dtd-schema","keywords":"dtd, schema, validation","author":{"@type":"Person","name":"EZ4Code Team"},"publisher":{"@type":"Organization","name":"EZ4Code","logo":{"@type":"ImageObject","url":"https://ez4code.com/logo.png"}},"datePublished":"2024-01-01","dateModified":"2026-08-01","image":"https://ez4code.com/og-image.png"}
XML

DTD and Schema

Document Type Definition for validation.

By EZ4Code Team
dtdschemavalidation

Code

<?xml version="1.0"?>
<!DOCTYPE note [
  <!ELEMENT note (to, from, heading, body)>
  <!ELEMENT to (#PCDATA)>
  <!ELEMENT from (#PCDATA)>
  <!ELEMENT heading (#PCDATA)>
  <!ELEMENT body (#PCDATA)>
  <!ATTLIST note priority CDATA "normal">
]>
<note priority="high">
  <to>Alice</to>
  <from>Bob</from>
  <heading>Reminder</heading>
  <body>Don't forget the meeting</body>
</note>

Explanation

A DTD declares the allowed element structure, content model, and attributes for an XML document, embedded inline or referenced externally. #PCDATA means parsed character text, and the comma sequence enforces child order. DTDs predate XML Schema and cannot express data types, so XSD is preferred for new work.

More XML Snippets