When data moves between systems, a single misplaced tag or a missing field can break an entire process. XML solved part of this problem by giving data a structured, tag-based format. But XML on its own does not check whether the structure makes sense. That job belongs to a Document Type Definition, or DTD. A DTD acts as a rulebook that tells a parser exactly what an XML document is allowed to contain, in what order, and with what attributes. For anyone working with structured data, metadata standards, or digital catalogues, understanding DTDs is a foundational skill.

Table of Contents

What is a DTD?

A DTD is a set of declarations that define the building blocks of an XML document. It specifies which elements are allowed, how they relate to one another, what attributes they can carry, and what kind of data each element can hold. When an XML file references a DTD, a parser checks the file against these rules. If the file follows every rule, it is considered valid.

Think of a DTD as a blueprint. The DTD specifies rules that control the structure of any XML file that references it. It can declare elements, attributes, entities, and notations, and it sets constraints on how each of these can be used. A document that does not follow these declarations fails validation.

This matters most when data is shared across multiple applications or organisations. A library catalogue exchanged between two systems needs a guarantee that every record contains a title, an author, and a publication year in a predictable arrangement. The DTD provides that guarantee. Without it, each system would have to guess at the structure, and errors would multiply quickly.

Why DTDs matter for structured data

DTDs are widely used in publishing, documentation, and metadata environments because they enforce consistency. A DTD provides a grammar for classes of documents by describing possible elements, attributes, and their relationships. When hundreds of records must follow the same structure, this grammar prevents drift. One author cannot suddenly invent a new tag or reorder fields, because the parser will reject the document.

This is especially relevant for information professionals. Bibliographic standards, archival metadata, and content management systems often rely on defined document structures. A DTD turns an informal agreement about “how a record should look” into a machine-enforceable rule.

How a DTD is structured

A DTD is attached to an XML document through a DOCTYPE declaration. This declaration appears near the top of the document, right after the XML declaration line. The name in the DOCTYPE must match the root element of the document. The DOCTYPE informs the parser that a DTD is associated with the document, and the body of the DTD then declares elements, attributes, entities, and notations.

There are two ways to attach a DTD. An internal DTD is written inside the XML document itself, enclosed in square brackets within the DOCTYPE declaration. An external DTD is stored in a separate file with a .dtd extension and referenced from the XML document. External DTDs are preferred when the same structure is shared across many documents, since a single rulebook can govern an entire collection.

Declaring elements

Elements are the core of any DTD. The <!ELEMENT> declaration defines an element and states what it can contain. For a simple element holding text, the content type is written as #PCDATA, which stands for parsed character data. For an element that contains other elements, the child elements are listed inside parentheses.

Consider a small example. Suppose we want a note with four parts in a fixed order:

<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

This DTD states that the root element note must contain exactly four children, in this exact sequence. The W3Schools reference shows that this DOCTYPE defines that the root element of the document is note and lists each permitted child. If a document places body before heading, or omits one of the four, it is invalid.

Special symbols control how often elements appear. A plus sign means an element must appear one or more times. An asterisk means zero or more times. A question mark means the element is optional and appears once or not at all. A comma separates a required sequence, while a vertical bar offers a choice between alternatives. These small symbols give a DTD considerable expressive power over structure.

Declaring attributes

Attributes attach additional information to an element. They are defined with the <!ATTLIST> declaration, which names the element, the attribute, the attribute type, and a default behaviour. A common pattern looks like this:

<!ELEMENT image EMPTY>
<!ATTLIST image height CDATA #REQUIRED>
<!ATTLIST image width CDATA #REQUIRED>

Here the image element carries two attributes, both holding character data, and both marked as required. The keyword #REQUIRED means the attribute must be present, while #IMPLIED would make it optional. This allows a DTD to enforce that every image record, for instance, always declares its dimensions.

Declaring entities

Entities are shortcuts. They let you define a piece of text once and reuse it throughout a document by reference. An internal entity is declared with the <!ENTITY> keyword and a value, then called using an ampersand and a semicolon. For example, declaring <!ENTITY hbd "happy birthday"> lets you write &hbd; anywhere in the document, and the parser expands it. Entities can also be external, pointing to a separate file through a SYSTEM or PUBLIC identifier, which is useful when the same content must be shared between multiple documents.

Creating a custom DTD

Designing a DTD begins with understanding the data you want to model. Suppose you are building a small catalogue of books. Each book has a title, an author, a year, and an ISBN. The first step is to identify the root element, then list its children and their content types.

An internal DTD for this catalogue might look like this:

<?xml version="1.0"?>
<!DOCTYPE catalogue [
<!ELEMENT catalogue (book+)>
<!ELEMENT book (title, author, year, isbn)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
]>

The book+ notation means the catalogue must contain at least one book and may contain many. Each book must have all four children in the stated order. A parser reading this DTD will reject any book missing a title or carrying an unexpected tag.

For larger projects, the same declarations would be saved in a file such as catalogue.dtd and referenced externally. The XML file would then begin with <!DOCTYPE catalogue SYSTEM "catalogue.dtd">. This separation keeps the rulebook in one place, so updating the structure means editing a single file rather than every document.

A note on DTD syntax and limitations

DTDs use a syntax that is different from XML itself. This is one of their well-known drawbacks. Because the syntax differs from XML, the same tools used to edit and parse XML cannot directly process a DTD. DTDs also lack support for namespaces and cannot specify precise data types such as integers or dates. A year, for example, can only be declared as character data, not as a number with a range.

These limitations led to the development of richer alternatives like XML Schema Definition (XSD). Even so, DTDs remain in use because of their simplicity, concise syntax, and widespread tool support. Many existing systems and document standards were built on DTDs, so understanding them is essential for working with legacy data and for grasping how XML validation evolved.

DTD versus well-formed XML

One of the most important distinctions in XML is the difference between a well-formed document and a valid document. These terms are often confused, but they describe two separate levels of correctness.

What makes a document well-formed

A well-formed XML document follows the basic syntax rules of XML. It has a single root element, every opening tag has a matching closing tag, elements are properly nested without overlapping, attribute values are quoted, and tags are case-sensitive. A document that breaks any of these rules is not well-formed and cannot be processed at all. Importantly, a well-formed document does not need a DTD. It simply has to obey XML’s universal grammar.

What makes a document valid

Validity is a stricter requirement. A document is valid only when it is well-formed and also conforms to the rules of an associated DTD or schema. As one explanation puts it, a well-formed XML document adheres to XML syntax rules while a valid document also conforms to the constraints specified in its DTD. The DTD checks that the right elements appear in the right order with the right attributes.

The relationship between the two is one-directional. Every valid document must be well-formed, but a well-formed document is not necessarily valid. The property of validity implies well-formedness, but not the other way around. A useful way to remember this: a valid document is a stricter version of a well-formed one, much like how a square is always a rectangle but a rectangle is not always a square.

There is also a practical trade-off. Processing a merely well-formed document is faster because the parser does not need to check anything against a DTD. Validation adds an extra layer of verification, and if a valid document is transmitted to another system, the DTD may need to travel with it. For data that stays within a single, trusted application, well-formedness may be enough. For data shared across systems where structure must be guaranteed, validation against a DTD becomes valuable.

Where DTDs fit in practice

DTDs remain relevant in document publishing, technical documentation, and structured authoring environments. They are commonly used in systems that handle large volumes of standardised content, where every document must follow an identical pattern. For information science students, DTDs connect directly to the broader idea of controlled structure in metadata and digital records. A catalogue, an archive, or a digital repository all benefit from rules that prevent inconsistent or incomplete records.

The takeaway is straightforward. A DTD turns an XML document from something that is merely syntactically correct into something that is structurally trustworthy. It moves data from “this looks like XML” to “this follows our agreed rules.” That shift is what makes large-scale data exchange reliable.

What do you think? If you were designing a DTD for a digital library catalogue, which fields would you make mandatory and which would you leave optional, and why? And in your own work, when would the simplicity of a DTD outweigh the richer features offered by XML Schema?

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

References
  1. https://www.ibm.com/docs/en/radfws/10.0.0?topic=dtds-document-type-definitions-overview
  2. https://www.sciencedirect.com/topics/computer-science/document-type-definition
  3. https://www.tutorialspoint.com/dtd/dtd_syntax.htm
  4. https://www.w3schools.com/xml/xml_dtd.asp
  5. https://www.tutorialspoint.com/dtd/dtd_entities.htm
  6. https://www.tutorialspoint.com/xml/xml_dtds.htm
  7. https://en.wikipedia.org/wiki/Document_type_definition
  8. https://www.brainkart.com/article/Well-Formed-and-Valid-Documents_8650/

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Information Processing & Retrieval

1 Intellectual Organisation of Information

  1. Intellectual Organisation of Information
  2. Meaning of Intellectual Organisation of Information
  3. Why IOI is Necessary?
  4. IOI in Indexing Systems
  5. IOI and Indexing Languages
  6. IOI in User Services
  7. IOI and Content Analysis
  8. Information Retrieval Systems – Changing Environment
  9. Future Trends

2 Indexing Languages–Part I – Concepts and Types, Subject Headings Lists and Thesauri

  1. Indexing and its Types
  2. Indexing Language
  3. Vocabulary Control
  4. Classification Schemes
  5. Subject Headings Lists
  6. Thesaurus
  7. Thesaurofacet
  8. Classaurus
  9. Sears List of Subject Headings
  10. Library of Congress List of Subject Headings

3 Indexing Languages–Part II- Classification Schemes

  1. Dewey Decimal Classification (DDC) Scheme
  2. Universal Decimal Classification (UDC) Scheme
  3. Library of Congress Classification (LCC) Scheme
  4. Colon Classification (CC) Scheme
  5. Bibliographic Classification (BC) Scheme
  6. Library Bibliographical Classification (BBK) Scheme
  7. Broad System of Ordering (BSO) Scheme
  8. Special Classification Systems

4 Indexing Systems and Techniques

  1. Indexing Principles and Process
  2. Pre-Coordinate Indexing Systems
  3. Post-Coordinate Indexing Systems
  4. Automatic Indexing
  5. Non-Conventional Indexing: Citation Indexing
  6. Web Indexing

5 Evaluation of Indexing Systems

  1. Purpose of Evaluation
  2. Levels of Evaluation
  3. Evaluation Criteria
  4. Recall and Precision
  5. Other Performance Measures
  6. Relevance
  7. Evaluation Methodology
  8. Evaluation Experiments

6 Principles and Evolution of Bibliographic Description

  1. Bibliographic Description: An Overview
  2. Scope and Objectives of Bibliographic Description
  3. Evolution of Bibliographic Description
  4. Ranganathan’s Principles
  5. ISBDs
  6. Bibliographic Formats
  7. Electronic Resource Description
  8. Models of Bibliographic Description
  9. Bibliographic Description: Entities, Attributes and Relationships

7 Rules for Bibliographic Description

  1. Bibliographic Description: Its Origin
  2. Development of Anglo-American Code
  3. The International Standard Bibliographic Description (ISBD)
  4. Impact of ISBD on Catalogue Codes
  5. Bibliographic Description for Non-Print Materials
  6. Guidelines for Bibliographic Description of Electronic Resources
  7. Guidelines for Bibliographic Description of Internet Resources
  8. Rules for Description of Electronic Resources in AACR2 Revision 2002

8 Standards for Bibliographic Record Format

  1. International Standard Bibliographic Description (ISBD)
  2. MARC Format
  3. UNIMARC
  4. Common Communication Format (CCF)
  5. Indian Standard

9 Metadata- MARC21-856 Field, Dublin Core, TEI

  1. MARC21 – 856 Field
  2. Dublin Core Metadata Initiative (DCMI)
  3. Text Encoding Initiative (TEI)
  4. Procedure of Electronic Resource Description

10 Norms and Guidelines for Content Development

  1. Introduction
  2. Needs and Guidelines
  3. Standards Related to Electronic Content
  4. W3C Recommendations
  5. Electronic Text Encoding and Interchange
  6. Dynamic Content

11 Introduction to HTML and XML

  1. World Wide Web and Markup Languages
  2. Standard Generalized Markup Language (SGML)
  3. HyperText Markup Language (HTML)
  4. Basic HTML Tags
  5. Linking
  6. URLs
  7. HTML and the Browser
  8. eXtensible Markup Language (XML)
  9. XML Syntax and Semantic Tags
  10. Document Type Definition (DTD)
  11. Implications of XML in Library and Information Activities

12 Web-based Content Development

  1. What can be done with World Wide Web?
  2. Hypertext, Hyperlink, and Hypermedia
  3. Hypertext Markup Language (HTML)
  4. Introduction to Dynamic HTML
  5. Web Interface to Database Linking
  6. Introduction to XML
  7. XML Document Design
  8. Multimedia Web Resources
  9. Web Servers
  10. Website Hosting
  11. Tools for Web Page Designing

13 Multilingual Content Development (Using Unicode)

  1. Character Representation in Computer
  2. American Standard Code for Information Interchange (ASCII)
  3. Indian Scenario and Indian Standard Code for Information Interchange (ISCII)
  4. UNICODE
  5. Web Content Development Through UNICODE
  6. Applications of UNICODE
  7. Applying UNICODE to the Libraries
  8. Problems Associated with UNICODE

14 ISAR Systems- Objectives, Types, Operations and Design

  1. Users and Their Information Needs
  2. Objectives of ISAR Systems
  3. Types of ISAR Systems
  4. Design of ISAR Systems
  5. Evaluation of ISAR Systems

15 Compatibility of ISAR Systems

  1. Need for Compatibility Among ISAR Systems
  2. Scope of Compatibility in ISAR Systems
  3. Areas of Compatibilities in ISAR Systems
  4. Principal Issues of Compatibility in ISAR Systems
  5. Compatibility of Online IR Systems
  6. Approaches Towards Compatibility in ISAR
  7. Quality Control and Compatibility

16 Intelligent Information Retrieval Systems

  1. Introduction
  2. Expert Systems
  3. Expert Systems for Information Processing and Retrieval
  4. Components of Expert Systems
  5. Knowledge Representation
  6. Knowledge Engineering
  7. Artificial Intelligence Based Decision Support Systems (DSS)
  8. Pattern Recognition

17 Information Retrieval Processes and Techniques

  1. Information Retrieval Systems
  2. Databases
  3. Information Retrieval Systems: Purpose, Components, and Functions
  4. Indexing and Information Representation
  5. Vocabulary Control
  6. Searching
  7. Information Seeking and User Interfaces
  8. Web Information Retrieval Systems
  9. Intelligent Information Retrieval

18 Information Retrieval Models and Their Applications

  1. Information Retrieval
  2. Information Retrieval Techniques
  3. Models Based on Input/Output
  4. Models Based on Theories and Tools

19 Search Strategies, Processes and Techinques

  1. Search File – An Essential Component
  2. Search Strategies and Pre-requisites
  3. Search Techniques
  4. The Information Search Process
  5. Online Searching
  6. How the Search Engines Work
  7. Common Search and Retrieval Features of Web Search Engines