What is the meaning of CDATA

后端 未结 5 1170
抹茶落季
抹茶落季 2020-12-15 06:51

Gurus,

I am self taught. There\'s a lot of what you enlightened ones call basic I know nothing about.

Reading this jQuery Tutorial

相关标签:
5条回答
  • 2020-12-15 06:56

    CDATA is character data which is ignored by the validator.

    You wrap things like javascript in CDATA tags so the your html validates (of course this is uncessary if you follow the more recent XHTML standards).

    0 讨论(0)
  • 2020-12-15 07:00

    Wikipedia sums it up really well:

    In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup. A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data that manifests as a CDATA section and character data that manifests as in the usual syntax in which < and & would be represented by &lt; and &amp;, respectively.

    The way I look at it, CDATA keeps the XML parser from sterilizing your code (making it display as just text, not code).

    I hope that explains some of it...

    0 讨论(0)
  • 2020-12-15 07:05

    This is a special sequence to allow inline javascript with special characters while still allowing the page to pass as valid xhtml. More details here. Essentially, don't worry about its exact meaning, but do put it in there!

    0 讨论(0)
  • 2020-12-15 07:06

    The reason for CDATA in this scenario is to allow the document to be loaded as straight XML. In XML the // will be treated as text instead of a comment and hence it will then see CDATA as an XML tag.

    0 讨论(0)
  • 2020-12-15 07:16

    With <![CDATA[ you can embed JS in XML (and XHTML) documents without the need to replace special XML characters like <, >, &, etc by XML entities &lt;, &gt;, &amp; etc to prevent that the XML syntax get malformed and that you get errors like The entity name must immediately follow the '&' in the entity reference. The general recommendation is however to put JS code in its own .js file which you then include by a <script src>.

    The <![CDATA[ is not needed in plain HTML documents. Unless you're developing with a XML based view technology like Facelets (for JSF) or ASP.NET MVC, there's absolutely no need to declare your HTML as XHTML. Just a <!DOCTYPE html> would suffice

    0 讨论(0)
提交回复
热议问题