Dear All,
I'm using the following code in my webpage to load an XML file into a set of arrays - for use by another
JS Application - but for some reason in Netscape it fails to find any elements in the XML file,
the code is :
Code:
var text = new Array();
var header = new Array();
var linka = new Array();
var targa = new Array();
var newsItems;
var xmldoc;
// for DOM2 including NN 6 & 7
if (document.implementation && document.implementation.createDocument)
{
// create the XML Doc
xmldoc = document.implementation.createDocument("", "", null);
// define a function to run on load
xmldoc.onload=function(){pop_ticker();}
}
// for IE
else if (window.ActiveXObject)
{
// create a new XML object for IE
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
// define some attributes of the doc
xmldoc.async = false;
// define a function to run on load
xmldoc.onreadystatechange=function(){if(xmldoc.readyState == 4){pop_ticker();}}
}
// for the rest
else
{
alert('Your browser can\'t handle this script');
}
//load the XML file in
xmldoc.load('news.xml');
// this is the function that populates the arryas from the XML so that the ticker will work
function pop_ticker()
{
// load the news items from the XML file
newsItems = xmldoc.getElementsByTagName("newselement");
// populate the Arrays from the XML file
for (var i=0;i<newsItems.length;i++)
{
// add the elements of the ticker item
text[i]=newsItems[i].getElementsByTagName("headline")[0].firstChild.data;
header[i]=newsItems[i].getElementsByTagName("newsitem")[0].firstChild.data;
linka[i]=newsItems[i].getElementsByTagName("newslink")[0].firstChild.data;
targa[i]=newsItems[i].getElementsByTagName("newstarget")[0].firstChild.data;
if (targa[i]=="a")
{
targa[i]="";
}
}
}
and a snippet of the XML file is :
Code:
<newsticker>
<newselement>
<headline>Stop invalid characters in Object Names</headline>
<newsitem>New Customisation</newsitem>
<newslink>customisations/fortyeight/</newslink>
<newstarget>a</newstarget>
</newselement>
<newselement>
<headline>DB Upgrade Status bug fix</headline>
<newsitem>New Customisation</newsitem>
<newslink>customisations/fortyseven/</newslink>
<newstarget>a</newstarget>
</newselement>
</newsticker>
any ideas ?