Back to the 2026 paper

Module I: Introduction to Web Technologies and Architectures

20267m

Explain the role of DTD in defining the structure of an XML document and discuss its relationship with XML.

Worked SolutionAI Assisted

DTD and XML

A Document Type Definition (DTD) specifies the permitted structure of an XML document. It declares allowed elements and attributes, their order and repetition, and entities. XML conforming to its DTD is valid; a well-formed XML document only needs to obey XML syntax.

Example:

<!DOCTYPE student [
  <!ELEMENT student (name, roll)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT roll (#PCDATA)>
]>
<student>
  <name>Raiyan</name>
  <roll>106</roll>
</student>

Here, a student element must contain name followed by roll; each contains parsed character data.

Types

  1. Internal DTD: declarations appear inside the XML document's DOCTYPE.
  2. External DTD: declarations are stored in a separate DTD file and referenced by the XML document.

Importance: DTDs standardize document structure, enable validators to detect missing or unexpected elements, document data expectations and support reusable entity declarations.

Limitations: DTD syntax is not itself XML, data types are limited, and namespace support is weak compared with XML Schema (XSD).

Remember: well-formed means syntactically correct XML; valid means well-formed XML that also conforms to a declared DTD or schema.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.