...

View Full Version : JavaScript & XML & NetScape



lmod
08-19-2005, 12:26 AM
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!!

Kor
08-19-2005, 11:20 AM
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].

Not exactly. Moz considers the gaps as possible textNodes, IE don't (at least not the first gap).

So that either you build a function which will removes the gaps or you use nodeType attribute to check whether a childNode is a textNode or not.

On the other hand, you must fill an empty tagged element with something if you want to use firstChild.nodeValue method. For instance use a nbsp

<div id="myid">&nbsp;</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum