W3C home > Mailing lists > Public > www-html@w3.org > April 2002

Re: Double hyphens ('--') in comments invalid

From: Andrew Clover <and@doxdesk.com>
Date: Mon, 29 Apr 2002 02:04:47 +0000
To: www-html@w3.org
Message-ID: <20020429020447.A24473@doxdesk.com>
Jimmy Cerra <jimbofc@yahoo.com> wrote:

> I'm not sure, but would this work????

> <?xml version="1.0">
> <script>
> <!-- <![ CDATA [
> /* some code with double dashes (--'s) */
> // ]]> -->

No. You can't declare a CDATA section inside a comment. You don't
want to put a comment in a <script> block in XHTML anyway - an XML
parser will ignore the lot.

If your aim is to embed non-XML code in an XHTML document such
that it will be compatible with HTML-3.2+ parsers as well as XML
parsers, you will need to write:

  <script type="text/javascript">//<![CDATA[[
    ...
  //]]></script>

  <style type="text/css">/*<![CDATA[[*/
    ...
  /*]]>*/</style>

If you also need commenting to hide the embedded content from pre-
HTML-3.2 tagsoup browsers, you will need the amusing hacks:

  <script type="text/javascript"><!--//--><![CDATA[//><!-- 
    ... 
  //--><!]]></script>

  <style type="text/css"><!--/*--><![CDATA[/*><!--*/ 
    ... 
  /*]]>*/--></style>

This is just a reminder that embedding is bad news and linking
will cause far less pain.

-- 
Andrew Clover
mailto:and@doxdesk.com
http://and.doxdesk.com/
Received on Sunday, 28 April 2002 22:08:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:15:51 GMT