简体   繁体   中英

In HTML, is the document type declaration an element?

In HTML, is the document type declaration an element?

I guess no, because in XML, the document type declaration <!DOCTYPE is part of the prolog and not an element. See https://www.w3.org/TR/xml/#sec-prolog-dtd and https://www.w3.org/TR/xml/#NT-doctypedecl and https://stackoverflow.com/a/55796040/156458

But The Definitive Guide to HTML5 by Adam Freeman says

The DOCTYPE element tells the browser it is dealing with an HTML document. This is expressed through the HTML boolean attribute:

 <!DOCTYPE HTML> 

No

In no precise, standards-oriented language is a DOCTYPE referred to as an element .

The Definitive Guide to HTML5 , despite its aspirational name, is being sloppy with terminology.

XML

The grammar for doctypedecl

doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'

is clearly distinct of, and incompatible with, that of element :

element   ::= EmptyElemTag | STag content ETag  
STag      ::= '<' Name (S Attribute)* S? '>'
Attribute ::= Name Eq AttValue
ETag      ::= '</' Name S? '>'

HTML5

The HTML5 specs have separate sections for DOCTYPEs ( WHATWG / W3C ) and elements ( WHATWG / W3C ) and never mangle terminology in any way that confuses DOCTYPEs with elements.

A document type declaration is a syntactic construct at the begin of the prolog of a markup document. In SGML, and by extension XML, a DTD tells the parser the document element (name of the "root" element of the document), and optionally contains or references markup declarations for the elements, attributes, entities, notations, short references (SGML only), and link rules (SGML only) used in the document.

An element , OTOH, is a logical construct, and formed by begin- and end-element tags .

In web browsers, doctype declarations have been used to express HTML version levels in quirky ways in the past, but HTML5 only accepts <!DOCTYPE html> or <!DOCTYPE html SYSTEM "about:legacy-compat"> .

In no way can a markup declaration be an element, and HTML as used in a doctype declaration isn't an attribute, let alone used as an HTML5-style boolean attribute. The author you cited has absolutely no idea what he is talking about.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM