www.webdeveloper.com
Results 1 to 2 of 2

Thread: Firefox Issue: XML brought in by Javascript coming up as null and undefined

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    20

    Question 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

  2. #2
    Join Date
    Sep 2009
    Posts
    20
    The issue has been resolved for the most part I had to change the .text to .getAttribute("name");

    and add this function to the loading of XML in firefox
    Code:
    function loop() {
    	if (document.getElementById("writeup_container").innerHTML == "")
    		setTimeout("displayXML()",1000);
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles