Connecting Tech Pros Worldwide Help | Site Map

GetElementByID oddness

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 09:35 PM
Toby White
Guest
 
Posts: n/a
Default GetElementByID oddness


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?

--
Dr. Toby White
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
Email: <tow21@cam.ac.uk>

  #2  
Old July 23rd, 2005, 09:35 PM
VK
Guest
 
Posts: n/a
Default Re: GetElementByID oddness



Toby White wrote:[color=blue]
> 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?
>
> --
> Dr. Toby White
> Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
> Email: <tow21@cam.ac.uk>[/color]

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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.