Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > using document.createElementNS or document.createElement

Reply
Thread Tools

using document.createElementNS or document.createElement

 
 
James Black
Guest
Posts: n/a
 
      05-21-2006
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.

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2006
James Black wrote:
> 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.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
James Black
Guest
Posts: n/a
 
      05-21-2006

Ian Collins wrote:

> > 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.


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.

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      05-21-2006
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: jsAyf.1727$(E-Mail Removed)

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>

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-21-2006


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
James Black
Guest
Posts: n/a
 
      05-21-2006

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.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2006
James Black wrote:
> 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 )...

--
Ian Collins.
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      05-22-2006
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>

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
James Black
Guest
Posts: n/a
 
      05-22-2006

Michael Winter wrote:
> 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;
?>

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      05-23-2006
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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Link Button to redirect to another page by using data from =?Utf-8?B?R1REcml2ZXI=?= ASP .Net 1 02-16-2005 07:04 PM
Error page using the Application_Error void dosnt work when using DIV for a please wait message s_erez@hotmail.com ASP .Net 2 12-24-2004 12:11 PM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Using GetOleDbSchemaTable to get SQL Server Field Description - using pete ASP .Net 1 08-29-2003 10:50 AM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM



Advertisments