Clever Geek Handbook
📜 ⬆️ ⬇️

DTD

DTD ( English Document Type Definition ) - includes two concepts:

  • A term that is used to describe a document scheme or part of it in the DTD scheme language .
  • DTD schema language (DTD schema language) is a computer language that is used to record the actual syntax rules for SGML and XML text markup languages . Since its introduction, other schema languages for specifications, such as XML Schema and RELAX NG , come with additional functionality.

Due to the differences between XML and SGML, the use of DTD also has some features depending on the target document.

Now there is a refusal to use DTD in XML technology for a number of reasons:

  1. Uses syntax other than XML.
  2. No typing of nodes.
  3. There is no support for namespaces.

DTD has been replaced by the W3C XML Schema Consortium standard .

Content

  • 1 Description of the document outline
    • 1.1 Declaring parameter objects
    • 1.2 Declaration of elements
    • 1.3 Definition of attributes
  • 2 Linking a document to a specific DTD
  • 3 Example
  • 4 See also

Document outline description

A DTD describes a document schema for a particular markup language by means of a set of declarations (parameter objects, elements, and attributes) that describe its class (or type) in terms of the syntactic restrictions of this document. Also, DTD can declare constructions that are always necessary to determine the structure of a document, but, however, can affect the interpretation of certain documents.

Declaring parameter objects

The declaration of a parameter object defines a macro of a certain type that can be referenced and which can be deployed somewhere in the DTD. These macros may not appear in the document itself, but only in the DTD. If a parameter object is referenced by the name of their DTD, then it is expanded to a line in which the contents of this object are indicated.

Examples:

  <! ENTITY% fontstyle "TT | I | B | BIG | SMALL">

The fontstyle parameter fontstyle contains a group of tags TT | I | B | BIG | SMALL TT | I | B | BIG | SMALL TT | I | B | BIG | SMALL .

  <! ENTITY% inline "#PCDATA |% fontstyle; |% phrase; |% special; |% formctrl;">

The inline parameter object contains text data and four more fontstyle , phrase , special and formctrl .

Item Declaration

Element declarations form a list of permitted element names in a document, and also determine information regarding tags (whether they are mandatory) and content models for each element.

Various keywords and symbols define the content of an element:

  • EMPTY - empty content
  • ANY - any content
  • , - indicates the order
  • | - separation of alternatives
  • () - grouping
  • * - any number of elements (zero or more)
  • + - at least one element (one or more)
  • ? - optional element availability (zero or one)
  • If not * , + or ? - there must be only one element

Examples:

  <! ELEMENT DL - - (DT | DD) +>

The DL element must contain one or more DT or DD elements in random order.

  <! ELEMENT FORM - - (% block; | SCRIPT) + - (FORM)>

A FORM element must contain one or more elements with a block parameter object or SCRIPT elements in arbitrary order, however, it is impossible to contain another FORM element.

Defining Attributes

A list of attributes can be associated with each element of a DTD document. To do this, the !ATTLIST directive is used, which indicates the name of the element with which the list of attributes and the parameters of each attribute can be associated: its name, type and default properties.

For example:

  <! ATTLIST MAP name CDATA #REQUIRED>

This example defines the name attribute for the MAP element. It is a must.

Attribute types are as follows:

  • CDATA (Character set of data) - the attribute value can be any character data
  • ID - the attribute value must be a unique identifier for the element
  • IDREF - the value of the element is a link to the element by its ID
  • IDREFS - the same as IDREF , but with the possibility of links not by one identifier, but by several
  • NMTOKEN - the attribute value can be a sequence of characters that is somewhat similar to the name (hence the name name token). This is a string that contains any combination of the characters that are allowed to be used for XML names.
  • NMTOKENS - attribute value is a list of values
  • ENTITY - the value is used to refer to an external entity.
  • ENTITIES - allows you to specify a list of external entities separated by spaces.
  • NOTATION - the attribute value may be one of the previously defined notations
  • NOTATIONS - allows you to specify a list of notations.
  • Listings and NOTATION-listings
  • ENUMERATION - sets the list of possible alternatives of values.

There are such default properties:

  1. IMPLIED - attribute value is optional;
  2. REQUIRED - the attribute value must be specified;
  3. FIXED - the value of this attribute is set as a constant in DTD and cannot be changed in the document;
  4. some specific default value.

Linking a Document to a Specific DTD

To associate a document with a specific DTD, you must specify the Document Type Declaration element at the beginning of the text of the document.

Depending on the location of the DTD, the Document Type Declaration can be of two types:

  • Internal subset of DTD

The set of DTD declarations is contained in the text of the document. For example:

  <! DOCTYPE foo [<! ENTITY greeting "helloworld"> ]>
 
 <! DOCTYPE bar [<! ENTITY greeting "helloworld"> ]>
  • External subset of DTD

The set of DTD declarations is located in a separate text file with the extension .dtd In this case, the link to the file can be made through the public identifier and / or through the system identifier. For example:

  <! - Validation of plain HTML 4.01 ->
 <! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN"
 "http://www.w3.org/TR/html4/strict.dtd">

Example

An example of a very simple XML DTD describing a list of people:

  <! ELEMENT people_list (person *)>
 <! ELEMENT person (name, birthdate ?, gender ?, socialsecuritynumber?)>
 <! ELEMENT name (#PCDATA)>
 <! ELEMENT birthdate (#PCDATA)>
 <! ELEMENT gender (#PCDATA)>
 <! ELEMENT socialsecuritynumber (#PCDATA)>

Starting from the first line:

  1. The <people_list> element contains any number of <person> elements. The <*> sign means that 0, 1 or more <person> elements inside the <people_list> element are <people_list> .
  2. The <person> element contains the <name> , <birthdate> , <gender> and <socialsecuritynumber> . The sign <?> Means that the element is optional. The <name> element does not contain <?> , Which means that the <person> element must contain the <name> element.
  3. The <name> element contains data.
  4. The <birthdate> element contains data.
  5. The <gender> element contains data.
  6. The <socialsecuritynumber> element contains data.

An example of an XML document using this DTD:

  <? xml version = "1.0" encoding = "UTF-8"?> 
 <! DOCTYPE people_list SYSTEM "example.dtd">
 <people_list>
    <person>
       <name>
          Fred bloggs
       </name>
       <birthdate>
          11/27/2008
       </birthdate>
       <gender>
          Male
       </gender>
       <socialsecuritynumber>
          1234567890
       </socialsecuritynumber>
    </person>
 </people_list>

See also

  • DOCTYPE Options for HTML 4.01
  • RELAX NG
  • XML Schema
Source - https://ru.wikipedia.org/w/index.php?title=DTD&oldid=94578125


More articles:

  • Pensioner (Academy of Arts)
  • The dancer and the thief (film)
  • Red Channels
  • Live File System
  • Williams FW14
  • Bus Street (St. Petersburg)
  • PHLX Semiconductor Sector
  • Bus Lane (St. Petersburg)
  • Extinguished Lights
  • 1805 in music

All articles

Clever Geek | 2019