DartmanX wrote:
I want to ensure that this page remains an XHTML 1.0 Transitional (or
Strict) page, in case some newbie removes the DOCTYPE or some slightly
more knowledgeable tries to change it to HTML 4.01 (which won't work
with the app).
So what do you want to do, simply parsing the string with the page
template for a DOCTYPE declaration to make sure the DOCTYPE declaration
is the one for XHTML 1.0 Transitional?
Or do you expect to be able to validate a string with markup against a
certain DTD?
Or is that page template loaded in a browser window and you want to use
the DOM to check whether there is a DOCTYPE declaration? For that you
can check e.g.
if (document.doctype) {
alert(document.doctype.name + '\r\n' + document.doctype.publicId +
'\r\n' + document.doctype.systemId)
}
where name would be
html
publicId
-//W3C//DTD XHTML 1.0 Transitional//EN
and systemId
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
for XHTML 1.0 Transitional.
But there is no requirement for document.doctype to be implemented in
HTML DOM implementations I think and IE/Win does not implement that
property. Mozilla however does, so does Opera 8. Not sure about support
in other browsers or older versions.
As for changing that with DOM methods, the W3C DOM Level 2 Core says:
"docType cannot be altered in any way, including through the use of
methods inherited from the Node interface, such as insertNode or
removeNode."
Mozilla 1.7 does not complain about doing
var newDoctype = document.implementation.createDocumentType(
'html',
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
);
if (document.doctype) {
document.doctype.parentNode.replaceChild(newDoctyp e, document.doctype);
}
but I don't think that change will achieve anything.
DOM Level 3 Core says something to that:
"This node can be set at document creation time and later changed
through the use of child nodes manipulation methods, such as
Node.insertBefore, or Node.replaceChild. Note, however, that while some
implementations may instantiate different types of Document objects
supporting additional features than the "Core", such as "HTML" [DOM
Level 2 HTML], based on the DocumentType specified at creation time,
changing it afterwards is very unlikely to result in a change of the
features supported."
--
Martin Honnen
http://JavaScript.FAQTs.com/