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.cr eateDocume nt("","",n ull);
xmlDoc.load(dataSource);
//myXMLHTTPRequest = new XMLHttpRequest();
//myXMLHTTPRequest.open("G ET", dataSource, false);
//myXMLHTTPRequest.send(nu ll);
//var xmlDoc = myXMLHTTPRequest.responseX ML;
}
var stringHobby = xmlDoc.documentElement.las tChild.fir stChild.no deValue;
var name = xmlDoc.getElementsByTagNam e("first") [0].firstC hild.nodeV alue;
document.getElementById("p opup").inn erHTML = name + "'s hobbies:\n" + stringHobby;
xmlDoc= document.implementation.cr
xmlDoc.load(dataSource);
//myXMLHTTPRequest = new XMLHttpRequest();
//myXMLHTTPRequest.open("G
//myXMLHTTPRequest.send(nu
//var xmlDoc = myXMLHTTPRequest.responseX
}
var stringHobby = xmlDoc.documentElement.las
var name = xmlDoc.getElementsByTagNam
document.getElementById("p
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
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
bol
ASKER
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;l eft:550;to p:25;width :100;heigh t:50" onmouseover="show(fullfile )" onmouseout="hide()">
function show(dataSource)
{
if (window.ActiveXObject) {
var xmlDoc = new ActiveXObject("Microsoft.X MLDOM");
xmlDoc.async = false;
xmlDoc.load(dataSource);
var stringHobby = xmlDoc.documentElement.las tChild.fir stChild.no deValue;
var name = xmlDoc.getElementsByTagNam e("first") [0].firstC hild.nodeV alue;
document.getElementById("p opup").inn erHTML = name + "'s hobbies:\n" + stringHobby;
}
else {
xmlDoc2= document.implementation.cr eateDocume nt("","",n ull);
xmlDoc2.load(dataSource);
// alert(xmlDoc2);
var x = xmlDoc2.getElementsByTagNa me("hobbie s")[0].fir stChild.no deValue;
var name = xmlDoc2.getElementsByTagNa me("first" )[0].first Child.node Value;
//alert(x);
document.getElementById("p opup").inn erHTML=x;
//document.getElementById( "popup").i nnerHTML=" blah blah blah";
//myXMLHTTPRequest = new XMLHttpRequest();
//myXMLHTTPRequest.open("G ET", dataSource, false);
//myXMLHTTPRequest.send(nu ll);
//var xmlDoc = myXMLHTTPRequest.responseX ML;
//var stringHobby = xmlDoc.documentElement.las tChild.fir stChild.no deValue;
// var name = xmlDoc.getElementsByTagNam e("first") [0].firstC hild.nodeV alue;
//document.getElementById( "popup").i nnerHTML = name + "'s hobbies:\n" + stringHobby;
}
var popwin = document.getElementById("p opup");
popwin.style.visibility="v isible";
}
function hide()
{
var popwin = document.getElementById("p opup");
popwin.style.visibility="h idden";
}
<img name=showHobbies src="" style="position:absolute;l
function show(dataSource)
{
if (window.ActiveXObject) {
var xmlDoc = new ActiveXObject("Microsoft.X
xmlDoc.async = false;
xmlDoc.load(dataSource);
var stringHobby = xmlDoc.documentElement.las
var name = xmlDoc.getElementsByTagNam
document.getElementById("p
}
else {
xmlDoc2= document.implementation.cr
xmlDoc2.load(dataSource);
// alert(xmlDoc2);
var x = xmlDoc2.getElementsByTagNa
var name = xmlDoc2.getElementsByTagNa
//alert(x);
document.getElementById("p
//document.getElementById(
//myXMLHTTPRequest = new XMLHttpRequest();
//myXMLHTTPRequest.open("G
//myXMLHTTPRequest.send(nu
//var xmlDoc = myXMLHTTPRequest.responseX
//var stringHobby = xmlDoc.documentElement.las
// var name = xmlDoc.getElementsByTagNam
//document.getElementById(
}
var popwin = document.getElementById("p
popwin.style.visibility="v
}
function hide()
{
var popwin = document.getElementById("p
popwin.style.visibility="h
}
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
bol
ASKER
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;l eft:550;to p:25;width :100;heigh t:50" onmouseover="show(fullfile )" onmouseout="hide()">
<div align=left style="left:50">
<p style="margin-left:100;mar gin-top:50 ;color:#FF FFFF;font- family:ari al">
<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;mar gin-top:15 0;color:#F FFFFF;font -family:ar ial"></div >
</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;l
<div align=left style="left:50">
<p style="margin-left:100;mar
<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;mar
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
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
bol
ASKER
xmlDoc2= document.implementation.cr
xmlDoc2.load(dataSource);
// alert(xmlDoc2);
var x = xmlDoc2.getElementsByTagNa
var name = xmlDoc2.getElementsByTagNa
//alert(x);
document.getElementById("p
//document.getElementById(