W3C home > Mailing lists > Public > www-validator@w3.org > August 2004

Re: Java script and validator... not the common endtag/backslash error

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Sat, 21 Aug 2004 21:04:15 +0300 (EEST)
To: Jari Porola <jariporola@yahoo.com>
Cc: www-validator@w3.org
Message-ID: <Pine.GSO.4.58.0408212035350.10391@korppi.cs.tut.fi>

On Sat, 21 Aug 2004, Jari Porola wrote:

> I have javascript which has writeln() statements and
> validator parses the content of the script.

As usual, telling the URL would save time and guesses.

But presumably you are using XHTML, where <script> elements have #PCDATA
as their content model, as opposite to CDATA in HTML. This means that
in XHTML parsing, the content is "parsed", in the XML sense, i.e. looking
for markup, including comment declarations.

> invalid comment declaration: found delimiter "'"
> outside comment but inside comment declaration
>
> d.writeln( '<!--' );

I wonder what particular situation causes exactly that. But in any case,
in #PCDATA the character pair <! starts a markup declaration, and then
you're in trouble. (In SGML or XML parsing, no attention is paid to
quotation marks or apostrophes in #PCDATA - they are just character data,
without starting a quoted string of any kind.)

> I know I can skip these by putting the script in
> separate file,

Yes, that's the best approach.

> but I can't do that since my PHP
> gerates the javascript. so I have PHP which generates
> javascript which generates javascript.

It's hard to guess what the situation really is. But anyway, if the use of
an external script file is excluded, then there are various options.
The theoretical option is a CDATA section. The practical way (if you care
about IE, for example, which is XHTML ignorant and doesn't grok CDATA
sections either) is to use workarounds that avoid the constructs that
trigger something in #PCDATA parsing. For example, generating the "<"
character in JavaScript in a manner that does not mention it literally
removes the particular problem mentioned above:

var lt = '\x3c';
d.writeln( lt + '!--' );

(If I didn't explain this clearly enough, you might check the explanation
in Finnish in Korpela & Linjama, "XHTML-käsikirja", Docendo, August 2004,
pages 727 - 728.)

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
Received on Saturday, 21 August 2004 18:04:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:14:08 UTC