Inside the "for each" loop I am getting a value that is empty. Here is
a sample program that illustrates the problem:

private function xmlTesting() : void
{
        var myXml:XML = new XML("<root><commands> \
                <command name='c1' > \
                        <options> \
                            <option name='o1'/> \
                            <option name='o2'/> \
                        </options> \
                    </command> \
                    <command name='c2' > \
                        <options> \
                            <option name='o3'/> \
                            <option name='o4'/> \
                            <option name='o5' /> \
                        </options> \
                    </command> \
                </commands> \
        </root>");

        var myXml2:XMLList = myXml.commands.command.(@name=="c2");
                        
        trace("t1=" + myXml2[0].options);
        trace ("t2=" + myXml2[0].options.option);
                        
        for each (var opt:XML in myXml2[0].options.option)
        {
            trace("t3=" + opt);
        }
}

Here is the output I see in the trace window:

t1=<options>
  <option name="o3"/>
  <option name="o4"/>
  <option name="o5"/>
</options>
t2=<option name="o3"/>
<option name="o4"/>
<option name="o5"/>
t3=
t3=
t3=

I don't understand why my value of "opt" in the "for each" loop shows
up as empty in the trace (t3). I must be missing something. Any help
appreciated. Thanks.

Reply via email to