Sobes.tech
Junior

What is DTD (Document Type Definition)?

sobes.tech AI

Answer from AI

DTD (Document Type Definition) is a syntax for defining the structure and elements of an XML document. It describes the permissible elements, their attributes, the order of their appearance, and their content.

Main components of DTD:

  • Element declarations: Define permissible element names and their content.
  • Attribute declarations: Define permissible attributes for each element, their types, and default values.
  • Entity declarations: Define named fragments of text or markup that can be reused.

Example of DTD:

<!ELEMENT book (title, author, year)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ATTLIST book
  isbn CDATA #REQUIRED
>

Where:

  • <!ELEMENT book (title, author, year)> defines a book element that must contain title, author, and year elements in the specified order.
  • <!ELEMENT title (#PCDATA)> defines a title element that can contain only plain text.
  • <!ATTLIST book isbn CDATA #REQUIRED> defines a mandatory isbn attribute for the book element with data type CDATA (character data).

DTD is used to validate the correctness of an XML document against a defined structure.

What is DTD (Document Type Definition)? — Java - sobes.tech