An analysis of the disadvantages of self-closing of XHTML tags _ experience Exchange

Source: Internet
Author: User
If you are familiar with XML-related development, you may also be accustomed to this writing, thinking that any element in XML that does not contain child nodes can be written in this way, so that no content in XHTML can be labeled as such. While XHTML theoretically allows any label to be written in a self-closing way, browser compatibility poses a new problem: IE cannot correctly identify the self-closing wording of certain tags.

Please try entering the following XHTML code and browsing in IE:

hello world

, you will find that you can only see the front of the hello and not the back of the world, this thing is very inexplicable. A lot of people may have had this problem, and it took hours to find a reasonable explanation.

The explanation comes from another code similar to this:

Hello<textarea></textarea> World</p></strong></code&gt, can you get a reasonable explanation for the display effect in IE? We were able to see the previous Hello normal display, and the following world was shown in textarea, which proves that IE did not correctly recognize that the TEXTAREA tag has since been closed, but when it is not closed, and the contents of the following are recognized as textarea internal content. </P><P> This time we understand why the previous code didn't see the world behind it, because it was identified as part of the script. This means that when we use XHTML, we cannot use self-closing notation as freely as XML, and only a handful of tags that do not need to be closed can be written in self-closing notation, and other labels are best used in pairs, even if they are not. </P><P> finally need to remind everyone is, in fact, mentally retarded parser not only IE has, many places may encounter due to parser not rigorous and caused problems, so we in the writing XHTML or to accommodate some old HTML inherited habits, You can't just write as if you think you're in the right way with real XML. Don't believe me? Then try one more: <code><strong><p>hello <br></br> World</p></strong></code , pay attention to the display effect in IE and opera. </p><p><strong>update: </STRONG> Some readers think that the example I cite is not in accordance with the XHTML specification, read the XHTML specification first. The Chinese translation of the empty Elements section is as follows: "A null element must either have an end tag or end with/>, such as <br/> or <textarea></textarea>, in which case you need to track debugging to find the problem is not easy, because the XML processing does not violate any specification, each step of the processing is semantic. It is also better not to
Written
, because it is true that some mentally retarded parser cannot be correctly identified simply because one space is missing.

  • 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.