Having an issue with a JavaScript function that is supposed to read an XML file.
function readXML()
{
alert("readXML");
if(xmlDoc.readyState == 4 || xmlDoc.readyState == 'complete')
{
for(var i=0; i < xmlDoc.getElementsByTagName("Question").length; i++)
{
var CurrentTuple = xmlDoc.getElementsByTagName("Question")[i];
var QuestionID = CurrentTuple.attributes.getNamedItem("QuestionID").value;
var CorrectAnswer = CurrentTuple.attributes.getNamedItem("CorrectAnswer").value;
alert(QuestionID +":"+ CorrectAnswer);
var OutputDisplayString = "";
for(var j=0; j< CurrentTuple.childNodes.length; j++)
{
//alert(CurrentTuple.childNodes[j].nodeName);
OutputDisplayString += CurrentTuple.childNodes[j].nodeName;
OutputDisplayString += "\n";
}
alert(OutputDisplayString);
}
}
}
About the XML FILE...
<?xml version="1.0" encoding="ISO-8859-1"?>
<Exam>
<Question QuestionID="Q001" CorrectAnswer="A">
<Description>Does a final member variable have to be initialized at the time it's declared?</Description>
<AnswerA>No</AnswerA>
<AnswerB>Yes</AnswerB>
<AnswerC></AnswerC>
<AnswerD></AnswerD>
</Question>
</Exam>
Next, I will show the output result of "alert(OutputDisplayString);" using Firefox.
#text
Description
#text
AnswerA
#text
AnswerB
#ext
AnswerC
#text
AnswerD
#text
I am comparing this result with what I get using IE.
---------------------------
Message from webpage
---------------------------
Description
AnswerA
AnswerB
AnswerC
AnswerD
---------------------------
OK
---------------------------
I'm trying to understand why I'm getting #text as a result in Firefox.
This seems to affect the accurate count of "CurrentTuple.childNodes.length".
If you have any insights on the #text result in Firefox or suggestions on how to get the correct count of child nodes, please share.