Web page Standard Beginner: The difference between XHTML and HTML

Source: Internet
Author: User
Tags cdata compact empty end lowercase object model
xhtml| Standard | beginners | difference | Web page

Because XHTML is an application of XML, some of the completely legitimate habits in SGML-based HTML 4 must be changed in XHTML.

  The document must be well choreographed

The choreography of good well-formedness is a new concept introduced in [XML]. Essentially, this means that the element must have an end tag, or it must be written in a special way (described below).

Elements must be nested, although the SGML rules stack illegally, but existing browsers generally allow cascading.

Correct: nested elements.

<p>here is a emphasized <em>paragraph</em>.</p>

Incorrect: cascading elements.

<p>here is a emphasized <em>paragraph.</p></em>

  Element and attribute names must be lowercase

XHTML documents must use lowercase for all HTML element and attribute names. Because XML is case sensitive, this difference is necessary. such as <li> and <LI> are different labels.

  For non-null elements, the end tag must be used

In SGML based HTML 4, some implicitly end-meaning elements allow the end tag to be ignored. In xml-based XHTML, this omission is not allowed. All elements must have an end tag, except for elements declared empty in the DTD.

Correct: The end of the element.

<p>here is-a paragraph.</p><p>here is another paragraph.</p>

Incorrect: element not closed.

<p>here is a paragraph.<p>here is another paragraph.

  Property value must be in quotation marks

All attributes must be in quotes, even numbers.

Correct: attribute value in quotation marks

<table rows= "3" >

Incorrect: property value not in quotation marks.

<table rows=3>

  Attribute minimization

XML does not support the minimization of attributes. Attribute value pairs must be fully written. Property names such as compact,checked cannot be specified in an element without specifying a property value.

Correct: No properties minimized

<DL compact= "compact" >

Incorrect: Minimizing properties

<DL compact>

  Empty element

An empty element must either have an end tag, or the start tag ends with/>. For example,<br/> or

Correct: An empty element that ends

<br/>

Error: Empty label not closed

<br>

  White-space character processing in a property value

For attribute values, the user agent deletes the boot and subsequent blank characters and converts one or more whitespace characters, including line breaks, to a single character space (an ASCII space in the western script), 3.3.3 of [XML].

  Script and Style elements

In XHTML, script and style elements are declared as #pcdata content forms, so,< and & are considered the beginning of identity, and entities such as &LT and & are viewed as entity references by XML handlers and are considered < and & respectively . Wrapping the contents of the script and style elements in the CDATA notation section avoids the expansion of these entities.

<script>
<! [cdata[
... unescaped script content ...
]]>
</script>

CDATA parts are recognized by XML handlers and are a node in the Document Object model. See the DOM Level 1 recommended standard [DOM] for section 1.3, 1.3.

The alternative is to use external script and style documents.

  SGML banned

SGML to the author's DTD can specify elements that are not allowed to appear inside an element. Such a ban is not possible in XML.

For example, the strict HTML 4 DTD prohibits any depth of the ' a ' element from nesting to another ' a ' element. Such a prohibition cannot be written in XML. Although these prohibitions cannot be defined in the DTD, some elements should not be nested. In the standardized Appendix B Appendix B is a summary of these elements.

  Elements with ' id ' and ' name ' attributes

The element of HTML 4 that defines the Name property has a A,applet,form,frame,iframe,img,and map. The id attribute is also introduced in HTML 4. Both of these properties are designed as fragment identifiers.

In XML, the fragment identifier is an ID type, and each element can have only one attribute of the ID type. Therefore, in XHTML1.0, the id attribute is defined as the ID type. To ensure that the XHTML1.0 document is a well-formed XML document, when defining a fragment identifier, the XHTML document must use the id attribute, even for those elements that previously used the name attribute. See the information in HTML compatibility Guidelines to ensure that XHTML documents are used in text/html media type, and these anchors are backward compatible.

Note that in XHTML 1.0, the Name property is not officially supported and will be deleted in later versions of XHTML.



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.