Link to home
Create AccountLog in
Avatar of jpking72
jpking72

asked on

Firefox, XML, and the DOM

I'm trying to load an XML document IN FIREFOX  into the DOM and output it through the innerHTML command. In IE it is trivial, but I can't get it to work with Firefox.  There are two approaches below, one is commented out.  Any suggestions?

             xmlDoc= document.implementation.createDocument("","",null);
                xmlDoc.load(dataSource);
           
            //myXMLHTTPRequest = new XMLHttpRequest();
            //myXMLHTTPRequest.open("GET", dataSource, false);
            //myXMLHTTPRequest.send(null);
            //var xmlDoc = myXMLHTTPRequest.responseXML;
            }
           
           var stringHobby = xmlDoc.documentElement.lastChild.firstChild.nodeValue;
            var name = xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue;
           document.getElementById("popup").innerHTML = name + "'s hobbies:\n" + stringHobby;    
           
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jpking72
jpking72

ASKER

this is weird, if I put an alert in it, the window pops up after I click ok, but if I take to alert out, the popup doesn't show.  (see below)

 xmlDoc2= document.implementation.createDocument("","",null);
             xmlDoc2.load(dataSource);
             
            // alert(xmlDoc2);
            var x = xmlDoc2.getElementsByTagName("hobbies")[0].firstChild.nodeValue;
            var name = xmlDoc2.getElementsByTagName("first")[0].firstChild.nodeValue;
             //alert(x);
            document.getElementById("popup").innerHTML=x;
            //document.getElementById("popup").innerHTML="blah blah blah";
           
How are you calling the script?  If it is part of a function then what calls the function?  If it is just in script tags then where on the page?

With that result the problem may be running before the page is completed.  This would stop it from "finding" the element with the ID popup.  That is just one way but let me see more script and get more details.

bol
Also, it sounds like these results might be going to a popup.  If that is the case tell me more about that.  When does it open?  How?  Some of that code will help too.

bol
There is an image, when the mouse goes over the image, the "show" function is called and the popup should appear.   On mouseout, the "hide" function is called.All of the javascript is between script tags within the head tags

<img name=showHobbies src="" style="position:absolute;left:550;top:25;width:100;height:50" onmouseover="show(fullfile)" onmouseout="hide()">
 
           function show(dataSource)
            {

           
           
            if (window.ActiveXObject) {
           
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
            xmlDoc.load(dataSource);
           
           
           var stringHobby = xmlDoc.documentElement.lastChild.firstChild.nodeValue;
            var name = xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue;
           document.getElementById("popup").innerHTML = name + "'s hobbies:\n" + stringHobby;
           
            }
           
            else {
           
             xmlDoc2= document.implementation.createDocument("","",null);
             xmlDoc2.load(dataSource);
             
            // alert(xmlDoc2);
            var x = xmlDoc2.getElementsByTagName("hobbies")[0].firstChild.nodeValue;
            var name = xmlDoc2.getElementsByTagName("first")[0].firstChild.nodeValue;
             //alert(x);
            document.getElementById("popup").innerHTML=x;
            //document.getElementById("popup").innerHTML="blah blah blah";
           
             
            //myXMLHTTPRequest = new XMLHttpRequest();
            //myXMLHTTPRequest.open("GET", dataSource, false);
            //myXMLHTTPRequest.send(null);
            //var xmlDoc = myXMLHTTPRequest.responseXML;
           
           
           
           //var stringHobby = xmlDoc.documentElement.lastChild.firstChild.nodeValue;
           // var name = xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue;
           //document.getElementById("popup").innerHTML = name + "'s hobbies:\n" + stringHobby;
            }
           
               
           
           
            var popwin = document.getElementById("popup");
            popwin.style.visibility="visible";

         
            }
           
           
            function hide()
            {
            var popwin = document.getElementById("popup");
            popwin.style.visibility="hidden";
            }
 
One more question.  What is the element with the id "popup"?  Let me see that html.  I'll look over your last post more but I need that info too.

bol
here is the html:

        </script>
       
    </head>
    <body bgcolor="#5B0161">

        <h1><font face="Verdana" color="#C6CCFA">Resume Viewer</font></h1>
        <form name = "thisform" action="#">
        <input type="button" value ="next resume"
        onclick = "getRes('next')">
        <input type="button" value="prev resume" onclick = "getRes('prev')"/>
        <input type="button" value ="send decision" onclick = "requestGET();"/>
        <input type="button" value ="print resume">
       
       
        <img name="showHobbies" src="" style="position:absolute;left:550;top:25;width:100;height:50" onmouseover="show(fullfile)" onmouseout="hide()">
       
        <div align=left style="left:50">
        <p style="margin-left:100;margin-top:50;color:#FFFFFF;font-family:arial">
            <input type="radio" name="decision" value="interview" />Interview
            <input type="radio" name="decision" value="manager" />to Manager
            <input type="radio" name="decision" value="reject" checked />Reject</p>
        </div>
        </form>
        <div id="popup" style="left:800px; top:50px; width:150px; height:70px;"></div>
        <div id="restext"></div>
       
        <br />
        <div id="serverResponse" style="margin-left:100;margin-top:150;color:#FFFFFF;font-family:arial"></div>
Thanks for the information.  It is helpful.

If you comment out the XMLHttp object part and just send "blah, blah, blah" to the element and show it what is the result?  I am hoping this will tell us if the problem is getting the response or putting it on the page.

What happens if you just fill in the content the AJAX script should be sending (i.e. the response) in the popup div?  I want to do this to make sure the div's CSS or other page elements aren't causing the issue.

It seems like you might have some CSS and html errors.  If your doctype really is an XHTML type and you are testing Firefox then these should be corrected.  That doctype and browser are more sensitive to invalid html and/or CSS.

What type of document is the datasource and what does the data look like?  I did test what I could and the div appears OK and the content was there.

Let me know if you have a question about any of this or need more info.

bol
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol