Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 17th, 2005, 02:27 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript & XML

I am creating a script that I will use to rotate flash banners, and will get the parameters from a XML file. This will eventually be incorporated into a .Net user control. For now I am just writing the client side script to get it working. The problem:

The below script works in IE, but I cannot get it to work in NN, FireFox etc.
Q1) Can anyone tell me why this does not work in NN, FireFox etc?
Q2) Can anyone tell me how to get the total node count from a XML file?

The Script:

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--

function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
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");
}

function createTable()
{
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>'

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


// -->
</SCRIPT>
</head>

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

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

Please refer to my questions above (Q1, Q2) as I stated this works fine in IE but not NN, FireFox etc.
 
Old August 24th, 2005, 08:24 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

hii Imod!!
plz try this one
totalnodes.length

for my xml file its working ,if possible u can provide sample xml too

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--

function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
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("intFlsAdSysblk.xml");
}

function createTable()
{
var x = xmlDoc.getElementsByTagName('Ad');

totalnodes=x[0].childNodes;
alert(totalnodes.length)
for(i=0;i<totalnodes.length;i++)
{alert(x[0].childNodes[i].firstChild.nodeValue)
}

}


// -->
</SCRIPT>
</head>

<body onLoad="importXML()">


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

*****urs xml file ****
<myfile>

<Ad>
 <val>vr1</val>
 <val>erd2</val>
 <val>2323</val>
</Ad>

<Ad>
 <val>test1</val>
 <val>valo2</val>
 <val>trim3</val>
</Ad>

 </myfile>

Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript & XML & NN lmod Javascript How-To 0 August 18th, 2005 03:16 PM
Javascript && keeps turnig into &amp;&amp; ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
XML from a DB recordset (removal of &lt;&gt;) Thodoris XML 3 July 13th, 2004 12:28 AM
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.