Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you have is not XML, but an XMLList, and it is perfectly acceptable.</p> <p>You don't need to loop through. You can get another XMLList like this. An XMLList is like an array of XML, but in this case you won't have fully formed nodes, but just the contents of all the attributes.</p> <p>It will go something like this:</p> <pre><code>var questionTxt:XMLList = yourQuestions.@txt;//yourQuestions contains your originalXMLList as shown above </code></pre> <p>Now, you can access each text element as:</p> <pre><code>var stem:String = String(questionTxt[0]); </code></pre> <p>If for some reason you absolutely <em>must</em> have an Array, you can do this:</p> <pre><code>var questions:Array = new Array(); for (var i:int = 0; i&lt; questionTxt.length(); i++) { questions[i] = questionTxt[i]; } </code></pre> <p>However, it looks like a lot of work for nothing, since you can simply use the XMLList as it is by accessing it with e4x. What is your full goal?</p> <p>I just looked at your question a bit more carefully, and all you really need to do is this:</p> <pre><code>protected var questions:XMLList; public function processXML(e:Event):void { myXML = XML(e.target.data); questions = myXML.question; // get number of questions trace(myXML.question.length()); } public function getQuestionAt( index:Number ):String { if (questions[index] == undefined) { throw new Error("Wrong index for question!!!"); } return questions[index].attribute('txt'); } public function get numberOfQuestions():int { return myXML.question.length(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload