S
Sevinfooter
I'm loading xml files in order to populate some <select> options from
an xml file. i only need to fill these dropdowns on page load, so am
using XML DOM to fill them. Here's basically what the source XML file
looks like, abridged to only one record:
<?xml version="1.0" encoding-"utf-8"?>
<pilots>
<pilot>
<name>some, name</name>
<weight>188</weight>
</pilot>
</pilots>
Now, the following function loads the information ( i have reasons for
only using the microsoft activeXObject as opposed to adding Netscape
functionality):
function loadXML(xmlFile, target) { //target is the name of the
select element
try{
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
} catch (e) {
alert(e);
}
xmlDoc.asyn = "false";
xmlDoc.load(xmlFile);
var xmlObj = xmlDoc.documentElement;
var obj = document.getElementById(target);
var CNodes, textNode, valueNode;
var j = xmlObj.childNodes.length;
CNodes = xmlObj.childNodes;
for (i = 0; i < j; i++) {
textNode = CNodes.firstChild;
valueNode = CNodes.lastChild;
var opt = document.createElement("OPTION");
obj.options.add(opt);
opt.innerText = textNodes.firstChild.nodeValue;
opt.value = valueNode.firstChild.nodeValue;
}
}
This fails at valueNode.firstChild.nodeValue. i have tried adding an
alert with that value in it before the opt.value line, but it fails as
well. the opt.innerText node is fine. Any ideas why this dies there?
an xml file. i only need to fill these dropdowns on page load, so am
using XML DOM to fill them. Here's basically what the source XML file
looks like, abridged to only one record:
<?xml version="1.0" encoding-"utf-8"?>
<pilots>
<pilot>
<name>some, name</name>
<weight>188</weight>
</pilot>
</pilots>
Now, the following function loads the information ( i have reasons for
only using the microsoft activeXObject as opposed to adding Netscape
functionality):
function loadXML(xmlFile, target) { //target is the name of the
select element
try{
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
} catch (e) {
alert(e);
}
xmlDoc.asyn = "false";
xmlDoc.load(xmlFile);
var xmlObj = xmlDoc.documentElement;
var obj = document.getElementById(target);
var CNodes, textNode, valueNode;
var j = xmlObj.childNodes.length;
CNodes = xmlObj.childNodes;
for (i = 0; i < j; i++) {
textNode = CNodes.firstChild;
valueNode = CNodes.lastChild;
var opt = document.createElement("OPTION");
obj.options.add(opt);
opt.innerText = textNodes.firstChild.nodeValue;
opt.value = valueNode.firstChild.nodeValue;
}
}
This fails at valueNode.firstChild.nodeValue. i have tried adding an
alert with that value in it before the opt.value line, but it fails as
well. the opt.innerText node is fine. Any ideas why this dies there?