S
SM
Hello,
I wrote a Javascript function that loads a xml file to access the
data. After the loading of the xml file, the function init() is called
(for testing purposes im only returning the number of elements)
The loading executes ok for IE and the init() function returns the
correct numbers of elements.
When i try to load the xml file in Firefox, the init() function
executes but the number of elements is always 0. I guess is because
Firefox can't read the xml correctly. But why?
I've try rewriting the code in all the ways possible with no success.
What's wrong with this simple?
Need help
Marco
function loadXML()
{
//For firefox and friends
if (document.implementation && document.implementation.createDocument)
{
alert('my name is Firefox');
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = init();
}
else if (window.ActiveXObject)
{
alert('my name is IE');
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4)
{
try { init(); }
catch(e) {alert('Error loading the XML file: ' + e.toString()); }
}};
} //end if
else
{
alert('i have no name
');
alert('Your browser can\'t load the XML file: ' + e.toString());
return;
} //end else if
xmlDoc.load("DB/discography_original.xml");
}
function init()
{
...
var cdElems = xmlDoc.getElementsByTagName('cd');
alert('# of CDs: ' + cdElems.length);
...
}
I wrote a Javascript function that loads a xml file to access the
data. After the loading of the xml file, the function init() is called
(for testing purposes im only returning the number of elements)
The loading executes ok for IE and the init() function returns the
correct numbers of elements.
When i try to load the xml file in Firefox, the init() function
executes but the number of elements is always 0. I guess is because
Firefox can't read the xml correctly. But why?
I've try rewriting the code in all the ways possible with no success.
What's wrong with this simple?
Need help
Marco
function loadXML()
{
//For firefox and friends
if (document.implementation && document.implementation.createDocument)
{
alert('my name is Firefox');
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = init();
}
else if (window.ActiveXObject)
{
alert('my name is IE');
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4)
{
try { init(); }
catch(e) {alert('Error loading the XML file: ' + e.toString()); }
}};
} //end if
else
{
alert('i have no name
alert('Your browser can\'t load the XML file: ' + e.toString());
return;
} //end else if
xmlDoc.load("DB/discography_original.xml");
}
function init()
{
...
var cdElems = xmlDoc.getElementsByTagName('cd');
alert('# of CDs: ' + cdElems.length);
...
}