Ok, here is my question; I want to parse the below xml document and assign
the correct answer text to a variable for example the following node has a value of 8
<answer correct = ‘y’>8</answer>
How do I identify that in my parsing function
<?xml version="1.0"?>
<quiz>
<title>Addition</title>
<items>
<item><question>What is 2 + 2=</question><theimage>Http://www.myURL.com</theimage><answer>6</answer><answer correct = 'y'>4</answer><answer>5</answer><answer>8</answer></item>
<item><question>What is 3 + 8=</question><theimage>Http://www.myURL.com</theimage><answer correct = 'y'>11</answer><answer>10</answer><answer>8</answer><answer>9</answer></item>
<item><question>What is 9 + 1 =</question><theimage>Http://www.myURL.com</theimage><answer>9</answer><answer correct = 'y'>10</answer><answer>7</answer><answer>8</answer></item>
<item><question>What is 4 + 4 =</question><theimage>Http://www.myURL.com</theimage><answer>5</answer><answer>6</answer><answer>7</answer><answer correct = 'y'>8</answer></item>
</items>
</quiz>
function onQuizData(success)
{
var quizNode=this.firstChild;
var quizTitleNode=quizNode.firstChild;
title=quizTitleNode.firstChild.nodeValue;
var i=0;
// <items> follows <title>
var itemsNode=quizNode.childNodes[1];
while (itemsNode.childNodes*)
{
var itemNode=itemsNode.childNodes*;
// <item> consists of <question> and one or more <answer>
// <question> always comes before <answer>s (node 0 of <item>)
var questionNode=itemNode.childNodes[0];
quizItems*=new QuizItem(questionNode.firstChild.nodeValue);
var theimageNode=itemNode.childNodes[1].firstChild.nodeValue;
quizItems*.image = theimageNode;
var a=2;
// <answer> follows <question>
var answerNode=itemNode.childNodes[a++];
while (answerNode)
{
var isCorrectAnswer=false;
if (answerNode.attributes.correct=="y")
isCorrectAnswer=true;
trace(answerNode)
quizItems*.addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
// goto the next <answer>
answerNode=itemNode.childNodes[a++];
}
i++;
}
gotoAndStop("Start");
}
var thequiz="reading.xml"
var quizItems=new Array();
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
//myData.load(xmlPath);
myData.load(thequiz);
stop();