Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2005, 03:16 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript & XML & NN

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.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 = (c);
}



</SCRIPT>
    </head>

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

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

Which also works!

Please Help!!








Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript & XML lmod Javascript 1 August 24th, 2005 08:24 AM
Javascript && keeps turnig into &amp;&amp; ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
xml & javascript shine XML 1 December 24th, 2003 12:45 PM
xml & javascript shine Javascript How-To 0 December 24th, 2003 07:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.