GetElementByID oddness

T

Toby White

Can ayone tell me what the expected behaviour of the
following snippet is:


<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:cml="http://www.xml-cml.org/schema/CML2/Core">
<head />
<body>
<cml:cml id='mol_1'/>
<p>
<script type="text/javascript">
//<![CDATA[
var mol_1 = document.getElementById('mol_1');
var para = document.createElementNS('http://www.w3.org/1999/xhtml','p');
if (mol_1) {
para.appendChild(document.createTextNode("Found mol_1"));
}
else
{
para.appendChild(document.createTextNode("Didn't find mol_1"));
}
document.getElementsByTagName('body')[0].appendChild(para);
//]]>
</script>
</p>
</body>
</html>


I find that, with firefox 1.0.4, and with Deer Park alpha 1,
if the file is named:
bug.html : "Found mol_1"
bug.xhtml: "Didn't find mol_1"
bug.xml : "Didn't find mol_1"

with Konqueror 3.3.2
bug.html : "Didn't find mol_1"
bug.xhtml: "Didn't find mol_1"
bug.xml : "Found mol_1"

And finally - can anyone tell me how I can reliably
get hold of the cml:cml element in javascript?
 
V

VK

Toby said:
Can ayone tell me what the expected behaviour of the
following snippet is:


<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:cml="http://www.xml-cml.org/schema/CML2/Core">
<head />
<body>
<cml:cml id='mol_1'/>
<p>
<script type="text/javascript">
//<![CDATA[
var mol_1 = document.getElementById('mol_1');
var para = document.createElementNS('http://www.w3.org/1999/xhtml','p');
if (mol_1) {
para.appendChild(document.createTextNode("Found mol_1"));
}
else
{
para.appendChild(document.createTextNode("Didn't find mol_1"));
}
document.getElementsByTagName('body')[0].appendChild(para);
//]]>
</script>
</p>
</body>
</html>


I find that, with firefox 1.0.4, and with Deer Park alpha 1,
if the file is named:
bug.html : "Found mol_1"
bug.xhtml: "Didn't find mol_1"
bug.xml : "Didn't find mol_1"

with Konqueror 3.3.2
bug.html : "Didn't find mol_1"
bug.xhtml: "Didn't find mol_1"
bug.xml : "Found mol_1"

And finally - can anyone tell me how I can reliably
get hold of the cml:cml element in javascript?

First you need to decide for yourselve what are you working with: with
HTML or XML/XMLT (what XHTML is I don't know, but must be mean
something to you).

XML by definition is *strictly structured DATA*, only data and nothing
but data. So what is your script doing there (as well as loose HTML
markup) ?

If you decide to use XML/XMLT sets, then the script (as well as any
layout) has to be in XML template. It works great, but currently only
for Firefox 1.0.3 and higher and Explorer 6.x

If you decide to use the conventional HTML, than you can get and parse
any XML data via XMLHttpRequest from the server. That currently gives
you the highest coverage between existing browsers, but *much* less
effective as XML/XMLT.

Also you can include your XML data right into page using XML Island:
<xml>
....
</xml>
The latter again is supported for sure by Firefox 1.0.3 and higher and
Explorer 6.x. I have no info about other pretendents.

So make you mind, depending of your choice there are people here to
help you.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top