Notes for writing XHTML labels

Source: Internet
Author: User

The img mark in XHTML should be written as follows: . This method is called self-closing, which is completely legal in XML.

If you are familiar with XML-related development, you may be used to this writing method, thinking that any element in XML that does not contain child nodes can be written in this way, the labels that do not have any content in XHTML can also be written in this way. In XHTML theory, of course, any label can be written in self-closing mode. However, browser compatibility brings about a new problem, that is, IE cannot correctly identify the self-closing method of some labels. String 8

Enter the following XHTML code and browse in IE: <p> hello <script type = "text/javascript"/> world </p>, you will find that you can only see the preceding hello but not the following world, which is quite undefined. Many people may have encountered this problem and could not find a reasonable explanation after several hours. String 4

The explanation is derived from another similar code: <p> hello <textarea/> world </p>. Do you have a reasonable explanation for the display effect in IE? We can see that the preceding hello is displayed normally, while the following world is displayed in textarea, which proves that IE does not correctly identify that the textarea tag has been disabled, but when it is not disabled, the following content is recognized as the content inside textarea.

At this time, we can see why the previous Code does not see the world, because it is recognized as part of the script. This shows that when we use XHTML, we cannot use the self-closing method as if we were using XML. Only a few labels that do not need to be closed can be self-disabled, other labels should be closed in pairs even if there is no content.


Finally, we need to remind you that, in fact, mentally retarded parser not only has Internet Explorer, but may encounter problems caused by not rigorous parser in many places, therefore, when writing XHTML, we still need to accommodate some old HTML inherited habits. It cannot be written as if the XML was as self-satisfied as the standard. Believe it? Try again: <p> hello <br> </br> world </p>. Pay attention to the display effect in IE and Opera.

XHTML specifications:

1. All tags must have an ending mark.

2. The element and attribute names of all tags must be in lower case.

3. All XML tags must be reasonably nested.

4. All attributes must be enclosed by quotation marks ("").

5. encode all <and & special characters

6. assign a value to all attributes

7. Do not make "--" in the comment content

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.