HTML-to-XHTML1.0 compatibility _ experience exchange

Source: Internet
Author: User
Tags processing instruction
HTML-to-XHTML1.0 Compatibility Guide 1 handling instructions

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

2 empty Element

Add a space before the null element Terminator/and>, as shown in figure , And. Also, use the minimal tag syntax, such
Because of the syntax allowed by another XML

Many existing user proxies may cause unreliable results.

3. Element minimization and empty Element Content

The content model is not an empty element. When the content model is empty (such as an empty title or paragraph), do not use a minimal form (such

, No ).

4. Embedded style sheets and scripts

If your style sheet uses <or & or]> or --, use an external style sheet. If your script uses <or & or]> or --, use an external script. Note that the XML analysis program will remove the comments without notice. Therefore, in the past, the annotation method was used to "hide" scripts and style sheets so that documents can be backward compatible, but may not work as expected during XML-based execution.

5 branch within the attribute value

Avoid using the branch and multiple space characters in the attribute values. The User Agent processes these situations differently.

6 Isindex

In the head section of the document, do not use more than one isindex element. The isindex element is not in favor of use, and the input element is in favor.

7 lang and xml: lang attributes

The lang and xml: lang attributes are used when the element language is specified. Xml: lang attributes are in front.

8. segment identifier

In XML, the end part identifier URI [RFC2396] in the form of "# foo" does not mean that the element has a property name = "foo ", an element has an attribute defined as the ID type, for example, the id attribute in HTML 4. Many HTML client programs do not support the ID type attribute in this way. Therefore, you can attach the same value to these two attributes to ensure backward and forward compatibility to the maximum extent. (Such ...).

In addition, because the valid value set of the ID type attribute is much smaller than the value set of the CDATA type attribute, the name attribute is changed to NMTOKEN. This attribute is limited to only the same value as the Name product in ID type or XML1.0 section 2.5. Unfortunately, the xhtml dtd cannot express this restriction. Because of this change, pay attention to the conversion of existing HTML documents. If the conversion value may change, the values of these attributes must be unique and valid in the Document. Any reference to these fragment Identifiers (either internal or external) must be updated.

Finally, do not approve of using the name attribute in a, applet, form, frame, iframe, img, and map elements. In future XHTML versions, it will be removed.

9-character encoding

Specify the character encoding in the document, and specify the encoding attribute in the xml declaration (for example. ) And use the http-equiv statement in meta (for example ). Xml Processing Instruction encoding attribute value before.

10 Boolean attribute

Some HTML user proxies cannot interpret Boolean attributes in full (non-minimal) form, which is required by XML1.0. Note that this issue does not affect the compatibility of the user agent with HTML 4. Includes the following attributes: compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, defer.

11 Document Object Model and XHTML

Document Object Model level 1 Recommendation Standard [DOM] defines Document Object Models of XML and HTML 4. HTML 4 Document Object Model requires that HTML element names and attribute names are returned in uppercase and lowercase. The object model of the XML document specifies that element names and attribute names are returned in the form they are specified. In XHTML 1.0, elements and attributes are specified in lowercase. There are two ways to deal with this significant difference:

Applications that use DOM to access text/html internet media-type XHTML documents can use html dom. They can also rely on these interfaces to return uppercase element names and attribute names.
Applications that use DOM to access text/xml or application/xml internet media-type XHTML documents can also use xml dom. element names and attribute names to be returned in lowercase. In addition, some XHTML elements can be excluded from 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. But not in XML. XHTML makes the element optional, rather than inserting external elements by the Document Author. Correspondingly, the application needs to adapt to this.

12. Use in attribute values &

When the attribute value contains the & symbol, it must be represented by the character entity reference (that is "&"). for example, when an element's href property points to a CGI script that receives parameters, it must be represented as a 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 stacked style sheets and XHTML

The level 2 Recommendation Standard [CSS2] defines the style attributes for analyzing the tree structure of HTML and XML documents. The analysis will lead to different visual or auditory effects, depending on the selector used.

The following technology can reduce this impact on the document without modifying the media types:

I. the CSS style sheet of XHTML should contain lower-case elements and attribute names.
2. In the table, the tbody element is inferred by the analyzer of the HTML user agent, but the analyzer of the XML user agent does not. Therefore, if the CSS selector is to be referenced, you should always explicitly add the tbody element.
3. In the XHTML address space, the user agent recognizes the "id" attribute as an ID attribute. Therefore, even if the user agent cannot recognize the DTD, the style sheet should be able to continue to use the "#" simplified selector syntax.
4. In the XHTML address space, the user agent recognizes the class attribute. Therefore, the style sheet should be able to structure and continue to use "." To simplify the selector syntax.
5. CSS defines different consistency standards for HTML and XML documents. HTML rules are used when XHTML documents are expressed in HTML, and XML rules are used when XHTML documents are 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.