GetElementByID oddness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Toby White

    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.getEle mentById('mol_1 ');
    var para = document.create ElementNS('http ://www.w3.org/1999/xhtml','p');
    if (mol_1) {
    para.appendChil d(document.crea teTextNode("Fou nd mol_1"));
    }
    else
    {
    para.appendChil d(document.crea teTextNode("Did n't find mol_1"));
    }
    document.getEle mentsByTagName( 'body')[0].appendChild(pa ra);
    //]]>
    </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.u k>
  • VK

    #2
    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.getEle mentById('mol_1 ');
    > var para = document.create ElementNS('http ://www.w3.org/1999/xhtml','p');
    > if (mol_1) {
    > para.appendChil d(document.crea teTextNode("Fou nd mol_1"));
    > }
    > else
    > {
    > para.appendChil d(document.crea teTextNode("Did n't find mol_1"));
    > }
    > document.getEle mentsByTagName( 'body')[0].appendChild(pa ra);
    > //]]>
    > </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.u k>[/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.

    Comment

    Working...