W3C home > Mailing lists > Public > www-validator@w3.org > October 2006

Re: XTHML 1.0 Strict validation of noscript

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Sun, 15 Oct 2006 23:04:48 +0300 (EEST)
To: Rui del-Negro <rmn@dvd-hq.info>
cc: www-validator@w3.org
Message-ID: <Pine.GSO.4.64.0610152234130.9107@mustatilhi.cs.tut.fi>

On Sun, 15 Oct 2006, Rui del-Negro wrote:

> <script type="text/javascript">
> <!--
> print_user_name();
> // -->

It is advisable to drop the "<!--" stuff, which is nothing but useless 
technobabble copied from old documents and no books. The days when it was 
useful, when there were browsers that failed to recognize <script> 
elements at all, were about a decade ago. In XHTML, the "<!--" actually 
starts a comment, so a browser is allowed to ignore everything between it 
and the "-->". Far from protecting anything, the technobabble creates a 
pointless risk.

> I get an error saying <noscript> isn't allowed there, and must be placed 
> inside an <ins>, <del>, <object> or some other tag (don't remember exactly 
> which right now).

The real reason is that you have <noscript> inside a <p> element. That's 
not allowed.

> Why? I mean, if scripting isn't active, the contents of the <noscript> block 
> will essentially behave as if they were within the containing element (in 
> this case a <p>), no?

That's the theory, but that's not important right now - it's not a 
validation issue.

> So why do I have to enclose it in an <ins> container 
> (for example)?

You don't. That would be a wrong move. First, it would be semantically 
wrong markup, because it's not really inserted content in the sense of 
being an addition to a previous version. Second, the document would 
definitely violate HTML specifications, even though it would do that in a 
manner that cannot be reported by a validator, due to lack of expressive
power in the DTD formalism. "The INS and DEL elements must not contain 
block-level content when these elements behave as inline elements."
And that's what you would need if you used <ins> as a trick to avoid the 
error message. Note that it's "must not", not just "should not".
See http://www.w3.org/TR/html401/struct/text.html#h-9.4

> Also, if, in addition to "dear user", I want to include an icon (i.e., an 
> <img>), the validator tells me images aren't allowed inside a <noscript>

No, the point is that an <img> element, as any text-level element, must 
not _directly_ appear as a sub-element ("child") of <noscript>, since the 
syntax allows block content only. Using <noscript><div><img 
...></div></noscript> would be syntactically OK (though not what you want, 
since <div> implies a line break before and after, as any block element 
does).

> Is this a bug in the validator, or just some strange "feature" of XHTML 1.0 
> Strict?

The latter, in a sense, but this is nothing new in XHTML. Even HTML 4 
defines <noscript> as a block element.

In practice, you need to duplicate text. Assuming you wish to make the 
greeting a <p> element (it's not really a paragraph by my book, but using 
<div> instead wouldn't change the point here), you need to write something 
like the following:

<script type="text/javascript">
  print_greeting();
</script>
<noscript>
<p>Hello dear user, and welcome to our site.</p>
</noscript>

so that print_greeting() adds a <p> element into the document tree, with 
the desired texts (including the user name picked up from somewhere)
as content. Note that it is _not_ correct to use document.write() in 
XHTML; instead, you are supposed to generate content by modifying the 
document tree via the DOM.

This need for duplication might be regarded as a design flaw in HTML. 
Client-side scripting was really introduced as a piece of adhockery and 
trickery rather than systematic design, not to mention logical design. 
But that's external to validation.

The validator only does what it has been told to do. It checks your 
document against a formalized syntax definition that you supply (normally 
by referring to a DTD), and it takes no position on the definition itself, 
e.g. whether it is useful or makes sense.

Actually, it now occurred to me that you could simply have e.g. the 
content

<p>Hello <span id="userref">dear user</span>, and welcome to our 
site.</p>

and a <script> element containing code that modifies the text content of 
the <span> element. This looks superior and removes the syntactic problems 
with <noscript>, since you don't need any <noscript>.

> The weird thing is that I'm pretty sure the first version of the code 
> validated fine two weeks ago, and the validator only started complaining 
> recently.

Such things often happen. You have changed something and you cannot quite 
trace back what the change was that made the markup invalid.

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
Received on Sunday, 15 October 2006 20:04:59 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:23 GMT