View Full Version : Unary decrement ruins validation

03-19-2004, 07:48 AM
Why is it that the W3 validator always chokes up on unary decrements?


It mistakes it for a comment declaration whether your javascript is within HTML comment declarations or not. Is the only solution to use i-=1 or work backwards using i++? I don't see why this throws an error if it's valid scripting.

03-19-2004, 08:04 AM
Did you enclose the codes in CDATA block?

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


/* ]]> */

03-19-2004, 08:10 AM
I was using the <!-- and -->. I've never seen this CDATA thing ever used in a script before. How widely known is it? I've never really commented my scripts out unless it was for sake of validation. What exactly is it and how is it interpreted? I've only seen it used in DTD files. Is this parsed by the browser or the validator?

03-19-2004, 08:25 AM
CDATA is required in XML for <, > and & to not be considered specialo characters. The only character sequence CDATA may not include, and whicdh will not be considered as raw character data, is ]]>

It's an XML structure, unnecessary in HTML. That's the reason we place it within comments.

As for <!-- --> not able to contain --, that is because -- was the toggle on/off comments in parser command sequences in SGML. In XML it may not be placed within parser command sequences, and must contain only a single comment.