DTD Resources
1. What is a DTD?
A Document Type Definition is the grammar of an SGML/XML markup language. It declares:
- elements and their content models,
- attributes and their allowed values/defaults,
- entities (shortcuts / special characters),
- notations (external, non-XML data formats).
A document that conforms to its DTD is valid; the parser uses the DTD to check this.
2. DTD Syntax — Content Model Building Blocks
| Symbol | Meaning | Example |
|---|---|---|
#PCDATA |
Parsed character data (plain text) | (#PCDATA) |
ANY / EMPTY |
Any content / no content | <!ELEMENT br EMPTY> |
, |
Sequence (required order) | (title, para+) |
| ` | ` | Choice (either/or) |
? |
0 or 1 time (optional) | (subtitle?) |
* |
0 or more times | (para*) |
+ |
1 or more times (mandatory) | (item+) |
(...) |
Grouping | `((a |
Element declarations:
<!ELEMENT book (title, author+, chapter+)>
<!ELEMENT para (#PCDATA | emph)*>
<!ELEMENT br EMPTY>
<!ATTLIST book isbn CDATA #REQUIRED
year CDATA #IMPLIED
lang NMTOKEN "en">
Attribute defaults: #REQUIRED (must supply), #IMPLIED (optional), value (default), #FIXED value (constant).
Entity declarations:
<!ENTITY copyright "© 2026 PYQDeck">
<!ENTITY % common "width CDATA #IMPLIED"> <!-- parameter entity (in DTD) -->
3. Internal vs External DTD
<?xml version="1.0"?>
<!-- external reference -->
<!DOCTYPE book SYSTEM "book.dtd">
<!-- or internal subset -->
<!DOCTYPE book [ <!ELEMENT title (#PCDATA)> ]>
| Type | Where the grammar lives | Use |
|---|---|---|
| Internal DTD | Inside the document | Small, single documents |
| External (public/system) | Separate shared file | Company-wide standard vocabularies |
4. Standard / Public DTD Resources (reusable grammars)
| Resource | Domain |
|---|---|
| HTML 4.01 DTDs (strict / transitional / frameset) | Web pages (pre-HTML5) |
| XHTML 1.0/1.1 DTDs | XML-flavoured HTML |
| MathML DTD | Mathematical formulae |
| SVG DTD | Vector graphics |
| DocBook DTD | Technical documentation / books |
| TEI DTD | Text encoding (humanities) |
| RSS / RDF DTDs | News syndication, metadata |
| Industry DTDs | HL7/CDA (health), LEGAL/XML courts, CALS (defence) |
Public identifiers: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5. DTD vs XML Schema (XSD)
| Aspect | DTD | XML Schema |
|---|---|---|
| Syntax | Non-XML | XML itself |
| Data types | Almost none (CDATA, ID, NMTOKEN) | Rich (int, date, string, patterns) |
| Namespaces | Not supported | Fully supported |
| Extensibility | Limited | High |
| Power | Enough for document structure | Preferred for data exchange |
6. Limitations of DTD
- No real data typing; no range/cardinality control beyond
? * +. - Not namespace aware; non-XML syntax; cannot express complex constraints (use XSD/RELAX NG).
7. Exam Points
- What is a DTD? Explain its purpose and components (elements, attributes, entities) — 7 marks.
- Write a small DTD and a matching valid XML document — 10 marks (very frequent).
- Internal vs external DTD; what are public DTD resources (HTML, MathML, DocBook)? — 5 marks.
- DTD vs XML Schema — 5 marks.