Parse HTML DocumentType Elements

Source: Internet
Author: User
Tags tidy

DOCTYPE is the abbreviation of Document Type. <! The DOCTYPE> element is used to declare the Document Type definition (DTD) of a page ). This element declaration is located at the beginning of the document, before the

The correct translation of W3C specifications should be recommended for W3C (W3C Recommendations ). Many designers see W3C as a standard. But many people are confused. The following lists the HTML and XHTML specifications in the W3C standards. The relationship between HTML and XHTML will be explained later.

XHTML can be viewed as the latest HTML specification and is an XML application that can be smoothly migrated from HTML 4.01. W3C restructured HTML 4.01 into XML in the first step, leading to the birth of XHTML 1.0. XHTML 1.0 depends on the semantics provided by HTML 4.01 labels.

Specifications and DTD

The <DOCTYPE> element declares different DTD to inform the browser of the HTML or XHTML specifications that the current page meets. The following lists the DTD related to HTML4.01 and XHTML1.0:

HTML 4.01 specifies three types of documents: Strict, Transitional, and Frameset.

  • HTML Strict DTD
  • Use this type if you need a clean flag to avoid confusion on the presentation layer. Please use it with the stacked style sheet (CSS:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  • HTML Transitional DTD
  • Transitional DTD can contain the rendering attributes and elements that W3C expects to move into the style sheet. If you use a browser that does not support Cascading Style Sheets (CSS), you must use the HTML Rendering feature:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  • Frameset DTD
  • Frameset DTD should be used for documents with frameworks. Except that the frameset element replaces the body element, the Frameset DTD is equivalent to the Transitional DTD:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML

XHTML 1.0 specifies three types of XML documents: Strict, Transitional, and Frameset.

  • XHTML Strict DTD
  • Use this type if you need a clean flag to avoid confusion on the presentation layer. Please use it with the stacked style sheet (CSS:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  • XHTML Transitional DTD
  • Transitional DTD can contain the rendering attributes and elements that W3C expects to move into the style sheet. If your readers use browsers that do not support Cascading Style Sheets (CSS) and you have to use the XHTML rendering feature, use this type:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • XHTML Frameset DTD
  • Use this DTD when you want to use the framework.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
DOCTYPE element syntax

Syntax: HTML top-level element availability "Registration/organization/type tag // Definition Language" "URL ".

Top-level element: specifies the type of top-level element declared in the DTD. This corresponds to the declared SGML document type. The default value is HTML.

Availability: Specifies whether the FPI is a publicly accessible object or a system resource. The value can be PUBLIC or SYSTEM. PUBLIC by default. Indicates publicly accessible objects. SYSTEM indicates SYSTEM resources, such as local files or URLs.

Registration: Specifies whether an organization is registered by the International Standardization Organization (ISO. + By default, the organization name is registered. -Indicates that the organization name is not registered. The Internet Engineering Task Group (IETF) and the World Wide Web Association (W3C) are not registered ISO organizations.

Organization: indicates the owner! DOCTYPE declares the name of the group or organization that creates and maintains the referenced DTD, that is, OwnderID. IETF is IETF. W3C is W3C.

Type: Specifies the public text class, that is, the referenced object type. The default value is DTD.

Definition: Specify the document type definition. Frameset framework set documentation. Strict exclude representative attributes and elements that W3C experts want to gradually remove because style sheets are well-developed. Transitional contains all content except the frameSet element.

Language: Specifies the public text language, that is, the natural language encoding system used to create the referenced object. The language definition has been written in the ISO 639 language code (two uppercase letters ). EN by default. English.

URL: Specifies the location of the referenced object.

DOCTYPE Switch

Modern browsers include different rendering modes to support both W3C-compliant Web pages and web pages designed for older browsers. Among them, the Standards (standard) mode (that is, the strict presentation mode) is used to present webpages that follow the latest Standards, while the Quirks (inclusive) mode (that is, the loose presentation mode or compatibility mode) used to present web pages designed for traditional browsers. In addition, note that Mozilla/Netscape 6 adds an Almost Standards (approximate standard) mode to support webpages designed for an earlier standard version.

Theoretically, this should be a very intuitive switch. Assume that the <! The DOCTYPE> element indicates that the page complies with the standard (such as XHTML1.0), and the browser will switch to the Standards mode. If doctype is not specified, or HTML 3.2 and earlier versions are specified, the browser switches to the Quirks mode. In this way, the browser can correctly display the documents that follow the standards, and will not completely discard the old-fashioned webpages that do not conform to the standards. However, there are the following situations:

  • Lost URL or relative URL
  • In the complete doctype declaration, you must include the URL of the Document Type Definition (DTD) file. If a URL is lost or a relative path (instead of a fully qualified Internet address) is specified, most browsers enter the Quirks mode, regardless of the mode specified by doctype.

  • Doctype with incorrect format
  • The browser is very sensitive to the form and format of doctype declarations. If a doctype with incorrect form cannot be identified, it will be forced to enter the Quirks mode (it is recommended to copy and paste a known and correct doctype to the document, rather than entering it in person ). A common cause for the format error of doctype is that a space is missing between the first part of doctype and the URL. Fold the doctype of a Two-row into a single row, and the space is often lost.

  • Doctype during the transition period
  • When the browser processes the doctype during the transition period, inconsistency is the most likely to occur. IE and Opera use Standards mode; Netscape 6 and older versions of Safari use Quirks mode; Netscape 7, Mozilla 1, and Safari use Netscape's Almost Standards mode, it is a version with better fault tolerance in Standards mode.

  • Unknown doctype
  • When processing unrecognized doctype, the browser is inconsistent. IE and Opera enter the Standards mode. In other words, it assumes that unrecognized doctype is a new standard that has not been integrated in the browser. On the contrary, Netscape 6 switches to the Quirks mode when encountering unrecognized doctype.

Doctype switching may be an effective way for the browser to enter the correct rendering mode and display the webpage correctly. The premise is that you have noticed the inconsistency between various browsers and can actively avoid various problems.

XHTML skills
  1. Followed by the preceding DOCTYPE declaration, An XHTML namespace statement is placed in the enhanced

    <Html xmlns = "http://www.w3.org/1999/xhtml">

  2. Because the XHTML 1.0 page is a legal XML document, and XML is case-sensitive for tags and attributes, all tags and attributes on the XHTML 1.0 page must be in lower case for simplicity.
  3. Some free tools such as HTML Tidy (http://tidy.sourceforge.net/) can help you to automatically convert tags and attributes to lowercase.

  4. You can add a <meta> element to the

    <Meta http-equiv = "Content-Type" content = "text/html; charset = gbk"/>

  5. In XHTML, all attributes must be enclosed by quotation marks.
  6. Some free tools such as HTML Tidy (http://tidy.sourceforge.net/) can help you automatically add quotation marks for all attributes.

  7. In XHTML, all attributes must have values. It cannot be written as in HTML 4.0: <input type = "checkbox" name = "shirt" value = "medium" checked>
  8. <Input type = "checkbox" name = "shirt" value = "medium" checked = "checked"/>

  9. In XHTML, all labels must be disabled. There are two ways to close a tag: Use the end tag to close the tag that contains the content, and add spaces and "/" to the blank tag "/". For example:
  10. <P> This is acceptable HTML and it is also valid XHTML. </p>

  11. Do not use "--" In comments "--". "--" Can only start and end with An XHTML comment and cannot appear in the comment content. The following statements are not allowed:
  12. <! -- Invalid -- and so is the classic "separator" below. --> <! ------------------------------------>

  13. Encode all special characters in HTML format.
  14. W3C XHTML, CSS, and DOM specifications constitute a complete and rigorous system. I call these three specifications the embodiment of the Trinity god in the Web world ". These three specifications represent the structure, presentation, and behaviour of the Web page. Strictly divide Web pages into these three layers and try to make the content of each layer independent of each other. This helps improve the reusability and modularization of pages and greatly reduce the cost of page creation, maintenance, and modification. To achieve the above layered goal, the written XHTML should only contain structure-related tags (elements and attributes ). Therefore, you should get used to using a Strict type DTD and discard the labels with meanings as soon as possible (these tags are marked as Deprecated in the HTML 4.0 specification, that is, "not advocate ", and will be completely discarded in Versions later than XHTML); discard the old table-based layout method as soon as possible and adopt the full CSS layout.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.