Using the following XML I am trying to construct an object for each Question which contains the questions attributes, the image name, and an all of the answers:
<?xml version=“1.0” encoding=“UTF-8”?>
<title name=“Chapter One”>
<question number=“1 of 5” format=“1” text=“The capital of Connecticut is Bloomfield”>
<choices>
<answer>False</answer>
</choices>
<img></img>
</question>
<question number=“5 of 5” format=“2” text=“What is the capital of Connecticut?”>
<choices>
<answer correct=“true”>Hartford</answer>
<answer correct=“false”>Bloomfield</answer>
<answer correct=“false”>New Haven</answer>
<answer correct=“false”>Washington D.C.</answer>
</choices>
<img>CTMap.jpg</img>
</question>
</title>
I have set up an array which loops through the XML and traces out each piece of information. I am having a problem with the answers array. I seem to be getting nothing for the first answer and only WashingtonDC for the second. Here is the code:
function buildQuestionArray() {
QuestionsArray = new Array ()
for (var i=0; i<TestNode.childNodes.length; i++){
curQuestion=TestNode.childNodes*;
for (var j=0; j<curQuestion.childNodes.length; j++){
curParts=curQuestion.childNodes[j];
var AnswersArray = new Array();
for (var b=0; b<curParts.childNodes.length; b++){
if (curParts.childNodes**.nodeName==null){
curImage=curParts.childNodes**;
}else if (curParts.childNodes**.nodeName!=null){
curImage=null;
curAnswers=curParts.childNodes**;
}
AnswersArray**= curAnswers.childNodes
}
}
QuestionsArray* = new Question (curQuestion.attributes.number, curQuestion.attributes.format, curQuestion.attributes.text, curImage, AnswersArray)
}
makeQuestion (currentQuestion);
}
function Question (numbers, format, Text, Image, Answers) {
this.numbers=numbers
this.Text=Text
_root.numbers_box.text=QuestionsArray[currentQuestion].numbers;
_root.Question_box.text=QuestionsArray[currentQuestion].Text;
trace (Text);
trace (format);
trace (Image);
trace (Answers);
}
when I run the movie this is what it traces:
The capital of Connecticut is Bloomfield
1
null
What is the capital of Connecticut?
2
CTMap.jpg
Washington D.C.
what I want it to trace is:
The capital of Connecticut is Bloomfield
1
null
False
What is the capital of Connecticut?
2
CTMap.jpg
Hartford, Bloomfield, New Haven, Washington D.C.