We help IT Professionals succeed at work.
Get Started

Help Trying to Iterate XML File in FLEX

chuela
chuela asked
on
646 Views
Last Modified: 2013-11-11
I don't know what I am doing wrong
I need to interate through each node of an XML document from a FLEX Module but it does not seem to work

The XML is loaded at the parent app
Here's the ActionsScript
And the XML as well
public var poll_xml:XML;
			public function init():void{
				poll_xml = new XML(parentApplication.pollresults);
				// Iterate through Each Poll Page
            	for each (var question:XML in poll_xml.*) {
            		Alert.show(question.name());
            		for each (var item:XML in question.*){
            			var lbl:Label;
	            		Alert.show(item.name());
						if (item.name()=="text"){
							lbl = new Label;
							lbl.htmlText = item + " Type:" + item.@type;;
							this.addChild(lbl);
						}
						
						if (item.name()=="answer"){
							lbl = new Label;
							lbl.htmlText = "Answer : " + item;
							if (item.@value!=null) lbl.htmlText += " Valor : " + item.@value;
							this.addChild(lbl);
						}
            		}
            		
            	}

			}





The XML :

<?xml version="1.0" encoding="utf-8"?>
<poll id="2" space="200">
	<question>
		<text number="false" type="text">El Nombre de la pregunta</text>
		<answer>UNa respuesta</answer>
		<answer>Otra respuesta en un repeater</answer>
		<answer>Otra por que no</answer>
		<answer>Otra MAs</answer>
	</question>
	<question>
		<text type="bars">El Nombre de la pregunta 2 </text>
		<answer value="120">Total Pregunta esta</answer>
		<answer value="200">Total Pregunta esta otra</answer>
		<answer value="30">Y esta</answer>
	</question>
	<question>
		<text type="pie">El Nombre de la pregunta 3</text>
		<answer value="80">Total Pregunta esta</answer>
		<answer value="50">Total Pregunta esta otra</answer>
		<answer value="110">Y esta</answer>
	</question>
</poll>

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE