Results 1 to 2 of 2

Thread: JavaScript & XML & NetScape

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    40

    Exclamation JavaScript & XML & NetScape

    I am trying to develop an App that will rotate Flash Movies without a postback. The Flash parameters are stored in a XML file and after loading the XML file I go through the nodes and build the string. I did not include the tags in the XML file (i.e. "<", ">" etc) because I thought it would be easy to just include them when I build the string in js. I AM NOT GOOD WITH JavaScript! (it would be easier to do this in .Net but I need the rotation to occur without postback) However after this script is debugged and working in IE, NN, FF etc. This will become apart of a .Net code behind file for a user control. Loading the xmlDoc works on IE, NN, FF etc. The problem is the function where I build the string:

    The Script:

    function createflsMovie()
    {
    var x = xmlDoc.getElementsByTagName('Ad');
    var flsStr = ' ';
    flsStr += '<' + x[0].childNodes[0].firstChild.nodeValue + x[0].childNodes[1].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[2].firstChild.nodeValue + x[0].childNodes[3].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[4].firstChild.nodeValue + x[0].childNodes[5].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[6].firstChild.nodeValue + x[0].childNodes[7].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[8].firstChild.nodeValue + x[0].childNodes[9].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[10].firstChild.nodeValue + x[0].childNodes[11].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[12].firstChild.nodeValue + x[0].childNodes[13].firstChild.nodeValue + ' ';
    flsStr += '> \n';
    flsStr += '<' + x[0].childNodes[14].firstChild.nodeValue + x[0].childNodes[15].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[16].firstChild.nodeValue + x[0].childNodes[17].firstChild.nodeValue + ' ';
    flsStr += '/' + '> \n';
    flsStr += '<' + x[0].childNodes[18].firstChild.nodeValue + x[0].childNodes[19].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[20].firstChild.nodeValue + x[0].childNodes[21].firstChild.nodeValue + ' ';
    flsStr += '/' + '>';
    flsStr += '<' + x[0].childNodes[22].firstChild.nodeValue + x[0].childNodes[23].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[24].firstChild.nodeValue + x[0].childNodes[25].firstChild.nodeValue + ' ';
    flsStr += '>';
    flsStr += '<' + x[0].childNodes[26].firstChild.nodeValue + x[0].childNodes[27].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[28].firstChild.nodeValue + x[0].childNodes[29].firstChild.nodeValue + ' ';
    flsStr += '> \n';
    flsStr += '<' + x[0].childNodes[30].firstChild.nodeValue + x[0].childNodes[31].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[32].firstChild.nodeValue + x[0].childNodes[33].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[34].firstChild.nodeValue + x[0].childNodes[35].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[36].firstChild.nodeValue + x[0].childNodes[37].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[38].firstChild.nodeValue + x[0].childNodes[39].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[40].firstChild.nodeValue + x[0].childNodes[41].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[42].firstChild.nodeValue + x[0].childNodes[43].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[44].firstChild.nodeValue + x[0].childNodes[45].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[46].firstChild.nodeValue + x[0].childNodes[47].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[48].firstChild.nodeValue + x[0].childNodes[49].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[50].firstChild.nodeValue + x[0].childNodes[51].firstChild.nodeValue + ' ';
    flsStr += '>' + '<' + '/' + 'EMBED>' + '<' + '/' + 'Object>'

    This works fine in IE (the movie plays in the browser) but I get nothing in NN, FF. (no exceptions or nothing)

    So I started to break the script down and noticed some things that are different:
    ex)
    In IE the first available Node would be [0]
    In NN it is [1].

    So I tried this in the loadXML();

    var c = 0
    function importXML()
    {
    if (document.implementation && document.implementation.createDocument)
    {
    xmlDoc = document.implementation.createDocument("", "", null);
    xmlDoc.onload = createTable;
    c++;
    }
    else if (window.ActiveXObject)
    {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) createTable()};
    }
    else
    {
    alert('Your browser can\'t handle this script');
    return;
    }
    xmlDoc.load("../ctrlTemp/xml/intAd/intFlsAdSysblk.xml");
    }

    Now the variable c would keep my node count and I figured that I would increase the value after each line.

    ex)
    flsStr += '<' + x[0].childNodes[c].firstChild.nodeValue;
    c++;
    flsStr += x[0].childNodes[c].firstChild.nodeValue + ' ';
    c++;

    etc.
    This also worked for IE and it would work for NN if I had only one line but for some reason the concactenations are not liked well by NN, also when I use c++ more that once NN does not like it either. It also seems that NN does not like the '<' + ... either. Can some one please enlighten me as to how to get this script NN friendly?

    Oh the output is like so:

    document.getElementById('flsAd').innerHTML = (flsStr);
    }



    </SCRIPT>
    </head>

    <body onLoad="importXML()">
    <form runat="server">

    <Div ID="flsAd"></Div>
    </form>
    </body>
    </html>

    Which also works!

    Please Help!!

  2. #2
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Re: JavaScript & XML & NetScape

    Hi Imod.... I am not familiar with NN at all, but I am with XML. You should try using an XSLT to transform your XML document into the required HTML rather than doing these loops and string concatenation. Check out my attached example (extract the files to the same location).

    Almost forgot. I have only tested this in IE, but the principle is the same. XSLT is standard (like XML).
    Attached Files Attached Files
    Last edited by shunt; Aug 25th, 2005 at 09:21 AM. Reason: Software Requirements

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width