HTML to XHTML1.0 Compatibility Guide _ Experience Exchange

Source: Internet
Author: User
Tags lowercase object model processing instruction
1 Processing Instructions

Some user agents display processing instructions. However, note that when there is no XML declaration in the document, the document can only be UTF-8 or UTF-16 with the default character encoding.

2 Empty elements

Add a space before the empty element terminator/and >, such as <br/>,
3 element minimization and empty element content

The content model is not an empty element, in an empty place (such as an empty title or an empty paragraph), not in a minimized form (such as with <p> </p> without <p/>).

4 embedded style sheets and script

If your style sheet uses < or & or]]> or-, use an external style sheet. If your script is in < or & or]]> or--with an external script. Note that the XML Analyzer will remove the contents of the annotation without being informed. As a result, the custom of "hiding" script and style sheets in a previously annotated way makes documents backward compatible, but may not work as expected in xml-based execution.

5 Internal branches in attribute values

Avoid the use of branches and multiple spaces in attribute values. The user agent does not work in the same situation.

6 Isindex

Do not use more than one ISINDEX element in the head section of the document. The Isindex element is not approved for use and is in favor of using the INPUT element.

7 lang and Xml:lang properties

Use the Lang and Xml:lang properties while specifying the language of the element. Xml:lang attribute in front.

8 Fragment Identifiers

In XML, ending fragment identifier URI [RFC2396] in the form of "#foo" does not mean that the element has an attribute name= "foo", but that the element has an attribute defined as an ID type, such as an id attribute in HTML 4. Many HTML clients do not support ID type attributes in this way, so you can attach the same value to both properties to ensure maximum backward and forward compatibility. (such as <a id= "foo" name= "foo" >...</a>).

In addition, the Name property is changed to NmToken because the set of legal values for the ID type attribute is much smaller than the set of values for the CDATA Type property. This property is limited to the same value as the name product in the ID type or XML1.0 2.5 section. Unfortunately, the XHTML DTD does not represent this limitation. Because of this change, you should take note when converting existing HTML documents. If the value of the conversion may change, the values of these properties must be unique in the document, valid, and any references to those fragment identifiers, whether internal or external, must be updated.

Finally, note that you are not in favor of using the name attribute in A,applet,form,frame,iframe,img, and in the map element, which will be removed in future XHTML versions.

9 character encoding

To specify the character encoding in the document, specify the encoding attribute in the XML declaration (such as. <?xml version= "1.0" encoding= "EUC-JP"?>) and use HTTP-EQUIV statements in meta (such as <meta http-equiv= "Content-type" content= ' text/html; charset= "Euc-jp" '/>). The encoding attribute value of the XML processing instruction is in the previous.

10 Boolean Properties

Some HTML user agents cannot interpret Boolean properties when they occur in full (not minimized) Form, which is XML1.0 necessary. Note that this issue does not affect the user agent's compatibility with HTML 4. Includes some of the following properties: Compact,nowrap,ismap,declare,noshade,checked,disabled,readonly,multiple,selected,noresize,defer.

11 Document Object model and XHTML

Document Object Model Level 1 recommends that the standard [DOM] defines the Document object model for XML and HTML 4. The HTML 4 Document Object model stipulates that HTML element names and property names are returned in uppercase form. The XML Document Object model specifies that element names and property names are returned in the form they are specified. In XHTML 1.0, elements and attributes are specified in lowercase. This significant difference can be dealt with in two ways:

Applications that access text/html Internet media type XHTML documents through the DOM can use the HTML DOM, and can also rely on the uppercase element names and property names returned by these interfaces.
Applications that access Text/xml or application/xml Internet media type XHTML documents through the DOM can also use the XML DOM. Element names and property names are returned in lowercase. Also, some XHTML elements may or may not be present in the object tree, because they are optional in the content model (such as the TBODY element in the table). In HTML 4, some elements can be minimized so that their start and end tags are ignored (SGML features), so it can happen. But not in XML. XHTML makes elements optional, rather than inserting foreign elements by document authors. Accordingly, the application needs to adapt to this.

12 using & in attribute values

When a property value contains a & symbol, it must be represented by a character entity reference (that is, "&"). For example, when an element's HREF attribute points to a CGI script that receives parameters, it must be represented as Http://my.site.dom/cgi-bin/myscript.pl?class=guest&name=user, not http ://my.site.dom/cgi-bin/myscript.pl?class=guest&name=user.

13 Cascading Style sheets and XHTML

Cascading style sheet Level 2 the recommended standard [CSS2] defines the properties of style, which is used to parse the tree structure of HTML and XML documents. An analysis of the impassability will result in different visual or auditory effects, depending on the selector used.

The following techniques can reduce this effect on a document without modifying the two media types:

XHTML CSS style sheets should be in lowercase elements and attribute names.
Second, in the table, the TBODY element is inferred from the HTML user Agent parser, but the parser for the XML user agent will not do so. So if you want to be referenced in a CSS selector, you should always add tbody elements clearly.
Third, in the XHTML name address space, the user agent will recognize the "id" attribute as an attribute of an ID type. Therefore, even if the user agent does not recognize the DTD, the style sheet should be able to continue to use "#" to simplify the selector syntax.
Iv. in the XHTML name address space, the user agent will recognize the class attribute, so the style sheet should be able to construct the continue use of "." Simplifies selector syntax.
CSS defines different conformance criteria for HTML and XML documents; An XML rule is used when an XHTML document is expressed in HTML, in HTML rules, in an XHTML document in XML.
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.