HTML to XHTML1.0 Compatibility Guide _ Experience Exchange

Source: Internet
Author: User
Tags processing instruction xml parser
1 Handling Instructions

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

2 Empty elements

Add a space before the empty element terminator/and >, as , And. Also, use the minimized label syntax, such as
, because another type of XML allows syntax

Many existing user agents can lead to unreliable results.

3 element minimization and empty element content

The content model is not an empty element, in an empty situation (such as empty title or empty paragraph), do not use the minimized form

No ).

4 embedded style sheets and script

If your stylesheet uses < or & or]]> or--, use an external style sheet. If your script is in < or & or]]> or--, use an external script. Note The XML parser removes the content of the comment without informing it. As a result, the habit of "hiding" script and style sheets in a previously annotated way makes documents backwards compatible, but may not work as expected in XML-based execution.

5 Internal branch of the attribute value

Avoid using branches and multiple spaces in attribute values. The user agent is not consistent in handling these cases.

6 Isindex

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

7 lang and Xml:lang properties

Both the Lang and Xml:lang properties are used when specifying the language of the element. The Xml:lang property is in front.

8 Fragment Identifiers

In XML, the end 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 a property that is defined as an ID type, such as an id attribute in HTML 4. Many HTML clients do not support the ID type attribute in this way, so you can attach the same value to both properties to ensure maximum backward and forward compatibility. (such as ...).

Additionally, because the set of legal values for the ID Type property is much smaller than the set of values for the CDATA Type property, the Name property is changed to NmToken. 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 cannot represent this limitation. Because of this change, be careful when converting existing HTML documents. If the conversion value may change, the values of these properties must be unique in the document, and any references to those fragment identifiers, whether internal or external, must be updated.

Finally, note that the name attribute is deprecated in a,applet,form,frame,iframe,img, and in the map element, and in later versions of XHTML it will be removed.

9 character encoding

To specify the character encoding in the document, use the encoding attribute specified in the XML declaration (for example,. ) and in Meta with the HTTP-EQUIV statement (e.g. ). The encoding attribute value of the XML processing instruction is in front.

10 Boolean Properties

Some HTML user agents cannot interpret Boolean attributes when they appear in a full (non-minimized) form, which is required by XML1.0. Note This issue does not affect the user agent's compatibility with HTML 4. Some of the following properties are included: Compact,nowrap,ismap,declare,noshade,checked,disabled,readonly,multiple,selected,noresize,defer.

11 Document Object model and XHTML

The Document Object Model Level 1 recommends the standard [DOM] to define the Document object model for XML and HTML 4. The HTML 4 Document Object model specifies that the HTML element name and attribute name are returned in uppercase. The XML Document Object model specifies that the element names and attribute names are returned in the form they are specified. In XHTML 1.0, elements and attributes are specified as lowercase. There are two ways to deal with this significant difference:

Applications that access the 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 attribute 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. The element name and property name 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 a table). In HTML 4, some elements can be allowed to be minimized so that their start and end tags are ignored (SGML feature), so it can happen. But not in XML. XHTML makes an element optional, rather than a foreign element that is inserted by the document author. Accordingly, the application needs to adapt to this.

12 using & in attribute values

When a & symbol is included in a property value, 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 a parameter, it must be represented as http://my.site.dom/cgi-bin/myscript.pl?class=guest&name=user, not an HTTP ://my.site.dom/cgi-bin/myscript.pl?class=guest&name=user.

13 Cascading Style sheets and XHTML

Cascading Style Sheets The level 2 recommended standard [CSS2] defines the properties of a style for parsing the tree structure of HTML and XML documents. Failure to analyze will result in different visual or auditory effects, depending on the selector used.

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

The XHTML CSS style sheet should use lowercase element and attribute names.
Second, in table, the TBODY element is inferred by the parser of the HTML user agent, but the parser for the XML user agent does not. So if you want to be referenced in a CSS selector, you should always add the tbody element with clarity.
Third, in the XHTML name space, the user agent will recognize the "id" attribute as an ID type attribute. Therefore, even if the user agent does not recognize the DTD, the stylesheet should be able to continue using "#" to simplify the selector syntax.
In the XHTML name space, the user agent will recognize the class attribute, so the stylesheet should be able to continue using "." Simplifies selector syntax.
CSS defines different consistency standards for HTML and XML documents; When an XHTML document is expressed in HTML, an XML rule is used with HTML rules when the XHTML document is expressed 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.