using document.createElementNS or document.createElement

J

James Black

It appears that this is actually a difference between whether to use
DOM2 or DOM1.

I am trying to write my programs using XHTML for the webpage, but, I
have to use DOM2 for xhtml 1.1.

Now, how much of a problem will this be for browser compatibility?

I am using a php script to change the mime type to be correct, either
application/xhtml+xml for Mozilla based browsers, and html for the
rest.

It appears that IE 6 works fine this way.

Is it wrong to just use namespaces as a norm?

Thank you very much for any responses.
 
I

Ian Collins

James said:
It appears that this is actually a difference between whether to use
DOM2 or DOM1.

I am trying to write my programs using XHTML for the webpage, but, I
have to use DOM2 for xhtml 1.1.
You don't have to, DOM2 is a superset of DOM1.
Now, how much of a problem will this be for browser compatibility?
You are better to stick with DOM1, DOM2 support isn't that flash in IE.
I am using a php script to change the mime type to be correct, either
application/xhtml+xml for Mozilla based browsers, and html for the
rest.

It appears that IE 6 works fine this way.

Is it wrong to just use namespaces as a norm?
Why bother? If all of your document is in one namespace, why the added
complexity? I haven't tried it, but I'd wager you will uncover all
sorts of browser compatibility issues.
 
J

James Black

Ian said:
Why bother? If all of your document is in one namespace, why the added
complexity? I haven't tried it, but I'd wager you will uncover all
sorts of browser compatibility issues.

I have two or three namespaces actually, as I am mixing mathml, and
perhaps svg, with my document.

That is why I had to look at using xhtml 1.1.

Thanx for the response.
 
M

Michael Winter

On 21/05/2006 02:22, James Black wrote:

[snip]
Now, how much of a problem will this be for browser compatibility?

Depending on what you're doing, you may need to write two separate
scripts: one for XHTML, one for HTML.
I am using a php script to change the mime type to be correct, either
application/xhtml+xml for Mozilla based browsers, and html for the
rest.

There have been a lot of very poor implementations[1] of MIME
type-oriented content negotiation that show complete disregard for RFC
2616. I hope you aren't using one of them (and identifying Mozilla
explicitly isn't particularly promising as other browsers support XHTML,
too).

[snip]

Mike


[1] XHTML or HTML 4
Author: Michael Winter
Group: alt.html
Date: 2006-01-15 22:58:23 GMT
Message-Id: [email protected]

The issue of content negotiation stops at my final post in that thread
(#45).

<http://groups.google.co.uk/group/alt.html/browse_frm/thread/d3dee15034ffc6e7/c1d909527cecdbe2>
 
M

Martin Honnen

James Black wrote:

I have two or three namespaces actually, as I am mixing mathml, and
perhaps svg, with my document.

That is why I had to look at using xhtml 1.1.

At least with Mozilla and with Opera you can only mix XHTML, SVG (and
for Mozilla also MathML) elements in documents served with an XML MIME
type like application/xml or text/xml or application/xhtml+xml. Then if
you want to script elements you should always use the namespace aware
methods of DOM Level 2 e.g.
document.createElementNS('http://www.w3.org/1999/xhtml', 'p')
for XHTML elements and e.g.
document.createElementNS('http://www.w3.org/2000/svg', 'circle')
for SVG elements as you are working with and building a namespace aware DOM.
 
J

James Black

Michael said:
There have been a lot of very poor implementations[1] of MIME
type-oriented content negotiation that show complete disregard for RFC
2616. I hope you aren't using one of them (and identifying Mozilla
explicitly isn't particularly promising as other browsers support XHTML,
too).

I will look at your link, but I look at the HTTP_ACCEPT header to
decide which of the two mime types to return.

It seems like the better way.

Later I may have the application tune itself more by having the
javascript check to see if the canvas is available, or is svg allowed,
or use a drawing api, and do the same with mathml.

It appears I will also need a switch to decide if I should use DOM1
or DOM2 on a particular application.
 
I

Ian Collins

James said:
Michael Winter wrote:

There have been a lot of very poor implementations[1] of MIME
type-oriented content negotiation that show complete disregard for RFC
2616. I hope you aren't using one of them (and identifying Mozilla
explicitly isn't particularly promising as other browsers support XHTML,
too).


I will look at your link, but I look at the HTTP_ACCEPT header to
decide which of the two mime types to return.

It seems like the better way.

Later I may have the application tune itself more by having the
javascript check to see if the canvas is available, or is svg allowed,
or use a drawing api, and do the same with mathml.

It appears I will also need a switch to decide if I should use DOM1
or DOM2 on a particular application.
I think you should check for specific DOM2 features and not use
hasFeature(). Some UAs are less than honest in what they report.

for example,

if( element.addEventListener )...
 
M

Michael Winter

On 21/05/2006 21:01, James Black wrote:

[snip]
I will look at your link, but I look at the HTTP_ACCEPT header to
decide which of the two mime types to return.

It seems like the better way.

It's the only (acceptable) way. However, 'looking at' the Accept header
certainly isn't as simple as a substring match. It needs to parsed and
the associated quality values (explicit and implicit) need to
considered. It's in this latter area that content negotiation mechanisms
seem to commit their worst offences.

One also needs to consider misbehaviour from MSIE. When sending a
request, it will issue an Accept header value similar to:

image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

As there is no quality value associated with the media range at the end
of the list (*/*), it means that everything is acceptable; only the
explicitly listed types have a higher preference[1]. For example,
text/html is technically just as useful to IE as application/xhtml+xml,
but of course that is far from the case. Similarly, when refreshing IE
will only send:

*/*

So, if a representation only matches using a media range, one should
favour the most universally compatible type. As far as HTML versus XHTML
is concerned, HTML is the obvious choice.

If you have written this negotiation mechanism yourself, you should
already have a very good working knowledge of HTTP. You /must/ have read
at least sections 3.7 Media Types, 12 Content Negotiation, and 14.1
Accept of the HTTP/1.1 specification [RFC2616] thoroughly and carefully.

[snip]

Mike


[1] More specific media types have preference over less specific
types and ranges. The HTTP/1.1 specification provides
examples of this.

[RFC2616] "Hypertext Transfer Protocol -- HTTP/1.1"
<ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt>
<http://www.rfc-editor.org/rfc/rfc2616.txt>
 
J

James Black

Michael said:
If you have written this negotiation mechanism yourself, you should
already have a very good working knowledge of HTTP. You /must/ have read
at least sections 3.7 Media Types, 12 Content Negotiation, and 14.1
Accept of the HTTP/1.1 specification [RFC2616] thoroughly and carefully.

I didn't write it myself, just modified it slightly to change what was
sent to the client (such as the DOCTYPE).

<?php
$charset = "iso-8859-1";
$mime = "text/html";
function fix_code($buffer) {
return (preg_replace("!\s*/>!", ">", $buffer));
}
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {

if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",$_SE
RVER["HTTP_ACCEPT"],$matches)) {
$xhtml_q = $matches[1];

if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVE
R["HTTP_ACCEPT"],$matches)) {
$html_q = $matches[1];
if((float)$xhtml_q >= (float)$html_q) {
$mime = "application/xhtml+xml";
}
}
} else {
$mime = "application/xhtml+xml";
}
}
if($mime == "application/xhtml+xml") {
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\"
?>\n<!DOCTYP
E html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML
2.0//EN\"\n\"http://www.w3.org
/TR/MathML2/dtd/xhtml-math11-f.dtd\" [\n <!ENTITY mathml
\"http://www.w3.org/199
8/Math/MathML\">]> ";
//
if($mime == "application/xhtml+xml") {
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\"
?>\n<!DOCTYP
E html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML
2.0//EN\"\n\"http://www.w3.org
/TR/MathML2/dtd/xhtml-math11-f.dtd\" [\n <!ENTITY mathml
\"http://www.w3.org/199
8/Math/MathML\">]>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">";
} else {
ob_start("fix_code");
$prolog_type = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01
Transition
al//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html
lang=\"en\">\n";
}
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
?>
 
M

Michael Winter

On 22/05/2006 12:08, James Black wrote:

[snip]
I didn't write it myself [...]
Acknowledged.

if (stristr($_SERVER["HTTP_ACCEPT"],
"application/xhtml+xml")) {

I would personally prefer the list to be parsed, but I suppose it will
do (just barely). Besides that, I detest writing parsers (it always
looks so messy) and it would be too much to post here.
if (preg_match(
"/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",

That regular expression is rather questionable and certainly doesn't
obey the "be liberal in what you accept" principle.

'/application\/xhtml\+xml\s*;\s*q\s*=\s*([01](?:\.\d*))/'

The single quotes are important, by the way; don't change them to
doubles without escaping the backslashes.

[snip]
if (preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",

That pattern should undergo similar changes (particularly because it's
broken).

[snip]
} else {
$mime = "application/xhtml+xml";

Once the regular expressions are fixed, this branch is more acceptable;
it could have been taken only because the quality values didn't have the
exact format specified. However, it would be better to make the q
parameter optional and, if absent, use the implicit value of 1.0.


In all, it's still not that good as it makes a lot of assumptions and
doesn't consider things like type and sub-type ranges, nor implicit
quality values. I wonder if there really are any /good/ implementations
to be found on the Web?
if($mime == "application/xhtml+xml") {
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\"
?>\n<!DOCTYP
E html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML
2.0//EN\"\n\"http://www.w3.org
/TR/MathML2/dtd/xhtml-math11-f.dtd\" [\n <!ENTITY mathml
\"http://www.w3.org/199
8/Math/MathML\">]> ";
//
if($mime == "application/xhtml+xml") {
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\"
?>\n<!DOCTYP
E html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML
2.0//EN\"\n\"http://www.w3.org
/TR/MathML2/dtd/xhtml-math11-f.dtd\" [\n <!ENTITY mathml
\"http://www.w3.org/199
8/Math/MathML\">]>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">";

Any particular reason why this is repeated?

[snip]

Mike
 
T

Thomas 'PointedEars' Lahn

Michael said:
In all, it's still not that good as it makes a lot of assumptions and
doesn't consider things like type and sub-type ranges, nor implicit
quality values. I wonder if there really are any /good/ implementations
to be found on the Web?

Probably one could implement Apache's MIME Content Negotiation algorithm
in PHP. It is free software and Open Source, after all :)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top