Morning All - I have some pretty standard code to iterate through a XML file and pull out data that matches an id variable. The IE browser works perfectly and returns the correct node values but Firefox will not. It returns undefined. It does return the correct node name when using “tagName” but when using .text to grab the string in the node ----nada.
Here’s the function:
function parseXML()
{
if (xmlDoc.readyState == 4)
{
if (xmlDoc.status == 200)
{
xmlDoc = xmlDoc.responseXML;
xmlObj = xmlDoc.getElementsByTagName(“region”);
for (var y = 0; y < xmlObj.length; y++)
{
if (xmlObj[y].getAttribute(“id”) == regID)
{
var hotelprice = xmlObj[y].getElementsByTagName(“hotelprice”)[0].text;
var pkgprice = xmlObj[y].getElementsByTagName(“pkgprice”)[0].text;
document.getElementById(“hotel”).innerHTML = “$”+hotelprice;
document.getElementById(“package”).innerHTML = “$”+pkgprice;
}
}
}
}
}
If anyone has any thoughts on this . . . please weigh in.
function parseXML()
{
if (xmlDoc.readyState == 4 && xmlDoc.status == 200)
{
xmlDoc = xmlDoc.responseXML;
regions = xmlDoc.getElementsByTagName("region");
for (var i = 0; i < regions.length; i++)
{
if (regions[i].getAttribute("id") == regID)
{
var browserName = navigator.userAgent;
var isIE = browserName.match(/MSIE/);
if (isIE)
{
var hotelprice = regions[i].childNodes[0].firstChild.nodeValue;
var pkgprice = regions[i].childNodes[1].firstChild.nodeValue;
}
else
{
var hotelprice = regions[i].childNodes[1].textContent;
var pkgprice = regions[i].childNodes[3].textContent;
}
document.getElementById("hotel").innerHTML = "$"+hotelprice;
document.getElementById("package").innerHTML = "$"+pkgprice;
}
}
}
}
I do have one more question for you though. I am opening two xml files on this page. I can get all the information from both in IE but again Firefox wants something other than this (which I know has to be bad coding)
Instead of the above, use the following for a cross-browser solution without sniffing:
var hotelprice = regions[i].getElementsByTagName("hotelprice")[0].firstChild.nodeValue;
var pkgprice = regions[i].getElementsByTagName("pkgprice")[0].firstChild.nodeValue;