Javascript with XHTML 1.0 strict?


J

Jonny

How can you validate Javascript generated HTML for XHTML 1.0 strict
compliance?

To avoid the "<" and "&" problem, all inline scripts MUST be enclosed
with either:
<!-- script --> Looked down upon at the w3 site.
//<![CDATA[ script //]]> Recommended.
Or put into an external js file.

However, when using any of these methods, you can use any none XHTML
1.0 strict stuff in a script like <center> and <br> instead of <br />
and still pass the w3 validation test.
http://validator.w3.org/

I've looked for info at w3 but I get the feeling that they have a low
opinion of Javascript. I'd like to use a XHTML 1.0 strict doctype with
my pages but why should I bother if they're not bothered with
Javascript. Is Javascript considered the shell suit of internet
fashion by the w3?
 
Ad

Advertisements

D

DU

Jonny said:
How can you validate Javascript generated HTML for XHTML 1.0 strict
compliance?

You can't ... if I understood your post correctly.

write() and writeln() methods "will produce a document which is not
necessarily driven by a DTD and therefore might be produce an invalid
result in the context of the document."

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634
To avoid the "<" and "&" problem, all inline scripts MUST be enclosed
with either:
<!-- script --> Looked down upon at the w3 site.
//<![CDATA[ script //]]> Recommended.
Or put into an external js file.

However, when using any of these methods, you can use any none XHTML
1.0 strict stuff in a script like <center> and <br> instead of <br />
and still pass the w3 validation test.
http://validator.w3.org/

Yes you can but you don't have to.

DU
 
R

Richard Cornford

DU said:
You can't ... if I understood your post correctly.

write() and writeln() methods "will produce a document which
is not necessarily driven by a DTD and therefore might be
produce an invalid result in the context of the document."

Mozilla apparently have decided not to implement the W3C HTML DOM
HTMLDocument interface on the document object in their XHTML DOM
implementation so with XHTML there are no write or writeln methods to
use.

OTOH Opera 7 have implemented HTMLdocument on their XHTML implementation
but it doesn't yet support script elements so there is no way of
executing a document.write inline as the page loads.

Which means that for XHTML (the real thing, not the strangely formatted
HTML served as text/html as per appendix c) the validity of the result
of a document.write is (and may remain) academic.
Yes you can but you don't have to.

In principal an XHTML UA would be perfectly entitled to throw an
exception while parsing invalid XHTML even if it resulted from a
document.write statement. And if the construction of the DOM used
methods such as appendChile (which seems likely) then they may throw
HIERARCHY_REQUEST_ERR exceptions if asked to add a CENTER element to the
DOM.

But from the scripting point of view the value in using valid HTML is
that it gives you the best chance of having a consistent DOM constructed
with standardised behaviour across-browsers. So hiding invalid HTML in
document.write statements in order to trick the W3C validator into
accepting nonsense mark-up will do nothing to promote that desire. And
if the author knows that the resulting document would be invalid then
what is the point of hiding the invalid mark-up from the validator, to
fulfil a contractual requirement for validity in name only? I wouldn't
be inclined to trust anyone who took that attitude.

Richard.
 
J

Jonny

DU said:
Jonny said:
How can you validate Javascript generated HTML for XHTML 1.0 strict
compliance?

You can't ... if I understood your post correctly.

write() and writeln() methods "will produce a document which is not
necessarily driven by a DTD and therefore might be produce an invalid
result in the context of the document."

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634
To avoid the "<" and "&" problem, all inline scripts MUST be enclosed
with either:
<!-- script --> Looked down upon at the w3 site.
//<![CDATA[ script //]]> Recommended.
Or put into an external js file.

However, when using any of these methods, you can use any none XHTML
1.0 strict stuff in a script like <center> and <br> instead of <br />
and still pass the w3 validation test.
http://validator.w3.org/

Yes you can but you don't have to.

DU

I understand that it's not its job to validate script and yes, I know
I don't have to use dodgy HTML. But no one can guarantee they won't
slip in a depreciated tag here or there, especially an old school
HTML'er like me.

Basically what I mean is:
Why is the 'dodgy' HTML displayed as I intended? What is responsible?
Does the browser, Opera 7.23, NS 7.1 and IE 6 - all guilty, over ride
the doctype if confused or whatever?

Should we, Javascript wise, leave XHTML 1.0 strict alone until things
improve?
 
D

David Dorward

Jonny said:
However, when using any of these methods, you can use any none XHTML
1.0 strict stuff in a script like <center> and <br> instead of <br />
and still pass the w3 validation test.
http://validator.w3.org/

Well yes - its an SGML validator. It doesn't have a JavaScript interpretor.
What would it do anyway - trigger every event handler in the document, and
insert every combination of text in every input and prompt, and do these
things in every possible order? It would take forever, or longer.
I've looked for info at w3 but I get the feeling that they have a low
opinion of Javascript.

What gives you that idea?
I'd like to use a XHTML 1.0 strict doctype with
my pages but why should I bother if they're not bothered with
Javascript.

Why should someone's opinion of JavaScript influence your use of another
technology?
Is Javascript considered the shell suit of internet
fashion by the w3?

JavaScript is a tool, more often then not its used poorly (when the same
task could be achieved better with other tools[1] or best not achieved at
all[2]), there are plenty of places when it can be useful.


[1] e.g. including a menu on multiple pages
[2] e.g. forcing a full screen window
http://www.stud.tu-ilmenau.de/~thla-in/scripts/fullscreen.jpg
 
J

Jim Ley

<!-- script --> Looked down upon at the w3 site.

no, it's not looked down upon, it just means a comment in XHTML and
the script would not be executed!
//<![CDATA[ script //]]> Recommended.

I don't agree with this. I'd recommend if you're going to embed to
escape your script, but use external
I've looked for info at w3 but I get the feeling that they have a low
opinion of Javascript. I'd like to use a XHTML 1.0 strict doctype with
my pages but why should I bother if they're not bothered with
Javascript.

Script is well supported in the doctype, what is not supported is
XHTML 1.0 in the real world - don't use it, if you're going to use
XHTML, use XHTML 1.1 absolutely no reason to limit yourself to 1.0

Jim.
 
Ad

Advertisements

M

Martin Honnen

Jonny said:
DU said:
Jonny wrote:

How can you validate Javascript generated HTML for XHTML 1.0 strict
compliance?
To avoid the "<" and "&" problem, all inline scripts MUST be enclosed
with either:
<!-- script --> Looked down upon at the w3 site.
//<![CDATA[ script //]]> Recommended.
Or put into an external js file.

However, when using any of these methods, you can use any none XHTML
1.0 strict stuff in a script like <center> and <br> instead of <br />
and still pass the w3 validation test.
http://validator.w3.org/

Yes you can but you don't have to.
I understand that it's not its job to validate script and yes, I know
I don't have to use dodgy HTML. But no one can guarantee they won't
slip in a depreciated tag here or there, especially an old school
HTML'er like me.

Basically what I mean is:
Why is the 'dodgy' HTML displayed as I intended? What is responsible?
Does the browser, Opera 7.23, NS 7.1 and IE 6 - all guilty, over ride
the doctype if confused or whatever?

Should we, Javascript wise, leave XHTML 1.0 strict alone until things
improve?

That has nothing to do with JavaScript, write an XHTML 1.0 document that
validates with the W3C validator to the script document type, then put
in some <embed> element, upload the page to a web server that sends the
file as text/html and I am sure all those browser will happily render
the page including the <embed> element.
When sending a page as text/html the browser doesn't even use an XML
parser to parse the page, and you have to send your XHTML as text/html
as IE doesn't even know how to treat application/xhtml+xml.
It seems you have fallen for the trap that XHTML 1.0 is superior to HTML
4.01 and think it is good to move there, even when it is served as
text/html to HTML user agents. Many people disagree on that, see
http://www.hixie.ch/advocacy/xhtml
and
http://www.hut.fi/u/hsivonen/xhtml-the-point
for instance.

To go even further, browsers like Netscape 7 respectively Mozilla or
like Opera 7 which accept application/xhtml+xml and then use an XML
parser do not use a validating parser at all, and you can even serve
application/xhtml+xml to them with an <embed> element (properly closed
with </embed> to have well-formed XHTML) for instance referencing a
flash movie and they will happily play that.

So, yes, leave XHTML alone, unless you have a real use for it, for
instance mixed namespace documents mixing XHTML with MathML and user
agents like Mozilla that know how to deal with that.
 

Top