Hubbry Logo
logo
Document type declaration
Community hub

Document type declaration

logo
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something to knowledge base
Hub AI

Document type declaration AI simulator

(@Document type declaration_simulator)

Document type declaration

A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document (for example, a web page) with a document type definition (DTD) (for example, the formal definition of a particular version of HTML 2.0 - 4.0). In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax.

The HTML layout engines in modern web browsers perform DOCTYPE "sniffing" or "switching", wherein the DOCTYPE in a document served as text/html determines a layout mode, such as "quirks mode" or "standards mode". The text/html serialization of HTML5, which is not SGML-based, uses the DOCTYPE only for mode selection. Since web browsers are implemented with special-purpose HTML parsers, rather than general-purpose DTD-based parsers, they do not use DTDs and never access them even if a URL is provided. The DOCTYPE is retained in HTML5 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers.

The general syntax for a document type declaration is:

or

The opening <!DOCTYPE syntax is followed by separating syntax (such as spaces, or (except in XML) comments opened and closed by a doubled ASCII hyphen), followed by a document type name (i.e. the name of the root element that the DTD applies to trees descending from). In XML, the root element that represents the document is the first element in the document. For example, in XHTML, the root element is <html>, being the first element opened (after the doctype declaration) and last closed.

Since the syntax for the external identifier and internal subset are both optional, the document type name is the only information which it is mandatory to give in a DOCTYPE declaration.

The DOCTYPE declaration can optionally contain an external identifier, following the root element name (and separating syntax such as spaces), but before any internal subset. This begins with either the keyword SYSTEM or the keyword PUBLIC, specifying whether the DTD is specified using a public identifier identifying it as a public text, i.e. one shared between multiple computer systems (regardless of whether it is an available public text available to the general public, or an unavailable public text shared only within an organisation). If the PUBLIC keyword is used, it is followed by the public identifier enclosed in double or single ASCII quotation marks. The public identifier does not point to a storage location, but is rather a unique fixed string intended to be looked up in a table (such as an SGML catalog); however, in some (but not all) SGML profiles, the public identifier must be constructed using a particular syntax called Formal Public Identifier (FPI), which specifies the owner as well as whether it is available to the general public.

The public identifier (if present) or SYSTEM keyword (otherwise) may (and, in XML, must) be followed by a "system identifier" that is likewise enclosed in quotation marks. Although the interpretation of system identifiers in general SGML is entirely system-dependent (and might be a filename, database key, offset, or something else), XML requires that they be URIs. For example, the FPI for XHTML 1.1 is "-//W3C//DTD XHTML 1.1//EN" and, there are 3 possible system identifiers available for XHTML 1.1 depending on the needs. One of them is the URL reference "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd". It means that the XML parser must locate the DTD in a system specific fashion, in this case, by means of a URL reference of the DTD enclosed in double quote marks.

See all
User Avatar
No comments yet.