what is html dtd

青灯夜游
Release: 2021-12-03 17:45:49
Original
4070 people have browsed it

In HTML, DTD refers to "Document Type Definition", which is a set of grammatical rules about tags, a verification mechanism for HTML files, and is part of the composition of HTML files. DTD can define legal XML document building blocks, which uses a series of legal elements to define the structure of the document.

what is html dtd

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

Document Type Definition (DTD) is a set of syntax rules for tags. It is part of the XML1.0 version specification, is the verification mechanism of html files, and is part of the composition of html files.

DTD can define legal XML document building blocks. It uses a series of legal elements to define the structure of the document.

DTD can be declared in an XML document as a line or as an external reference.

Internal DOCTYPE declaration

If the DTD is included in your XML source file, it should be wrapped in a DOCTYPE declaration using the following syntax:

<!DOCTYPE root-element [element-declarations]>
Copy after login

Example of XML document with DTD (please open in IE5 and higher, and choose to view source code):

<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don&#39;t forget me this weekend</body>
</note>
Copy after login

Open this XML file in your browser, and choose " View source code" command.

The above DTD is explained as follows:

  • !DOCTYPE note (second line) defines this document as a note type document.

  • !ELEMENT note (third line) defines the note element as having four elements: "to, from, heading,, body"

  • !ELEMENT to (the fourth line) defines the to element as "#PCDATA" type

  • !ELEMENT from (the fifth line) defines the from element as "#PCDATA" type

  • !ELEMENT heading (line 6) defines the heading element as "#PCDATA" type

  • !ELEMENT body (line 7) defines the body element as "# PCDATA" type

External Document Declaration

If the DTD is located outside the XML source file, then it should be encapsulated in a DOCTYPE definition:

<!DOCTYPE root-element SYSTEM "filename">
Copy after login

This XML document is the same as the above XML document, but has an external DTD: (Click to open the file and select the "View Source Code" command.)

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don&#39;t forget me this weekend!</body>
</note>
Copy after login

This is the "note.dtd" file containing the DTD:

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

Why use DTD?

  • With a DTD, each of your XML files can carry a description of its own format.

  • With DTD, independent groups can consistently use a standard DTD to exchange data.

  • Your application can also use a standard DTD to verify data received from the outside.

  • You can also use DTDs to validate your own data.

DTD has three document types: S (Strict), T (Transitional), and F (Frameset).

  • #Strict: Use this type if you need clean markup without clutter in the presentation layer. Please use with Cascading Style Sheets (CSS)

  • Transitional: DTD can contain rendering attributes and elements that the W3C expects to be moved into the style sheet. If your readers are using browsers that do not support Cascading Style Sheets (CSS) and you have to use HTML's rendering features use

  • #Frameset: DTD should be used with Framework documentation. Except that the frameset element replaces the body element, the Frameset DTD is equivalent to the Transitional DTD

html5 basically does not have the strict requirements of XHTML 1.0 Transitional, and has simplified many things and can be used directly <!DOCTYPE HTML>

Recommended tutorial: "html video tutorial"

The above is the detailed content of what is html dtd. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!