Firefox Issue: XML brought in by Javascript coming up as null and undefined
I'm relatively new to Javascript, I've worked in Actionscript 3.0 so I kinda have the hang of syntax, but I'm having an issue with my code working in firefox.
Code:
function loadXML()
{
var article = "clientInformation.xml"
// Load XML from a file on the web server
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async="false";
while (xmlDoc.readyState != 4) {} // readyState will be set to 4 when the document is loaded
xmlDoc.load(article);
displayXML();
}
else if (document.implementation && document.implementation.createDocument) // Broken
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.async="false";
xmlDoc.onload = displayXML();
xmlDoc.load(article);
alert("Is this happening?");
}
}
//on first load
function displayXML()
{
document.getElementById("writeup_container").innerHTML = xmlDoc.getElementsByTagName("company").item(0).text;
imageURL = xmlDoc.getElementsByTagName("company")[0].attributes.getNamedItem("image").text;
document.getElementById("image_container").innerHTML = "<img src=\"images/ClientSites/" + imageURL + "\"/>"
}
So I have an XML file with information that I want displaying in specific DIVs but when I run it in Firefox The Alert isn't even appearing at one point I had another else alerting if the page couldn't support the script but it wasn't appearing in firefox either.
The Error I'm getting was:
Error: xmlDoc.getElementsByTagName("company").item(0) is null
Line: 34
Code:
document.getElementById("writeup_container").innerHTML = xmlDoc.getElementsByTagName("company").item(0).text;
So there's my problem, any help would be apprecieated, I'm not a hardcore coder so any code please explain what it does <3