2 Replies Latest reply on May 11, 2010 10:24 AM by ssettlemyre

    E4X descendant-access (..) not working in simple case. Why?

    ssettlemyre

      I have a fairly simple case where I'm trying to use E4X to access some grandchildren in my xml file. The data is coming from an HTTPService POST, and I have the resultformat set to E4X. Are there any other things I should look out for? I've worked with E4X a bunch in AS3 and have never had a problem before.

       

      I'm trying to get the Exercise tags in a for loop

      for each (var node:XML in xml..Exercise) {

      ...

      }

       

      but xml..Exercise yields an empty XMLList.

       

      Here is my sample xml:

      <StudentProfile UserID="22" RoleID="1" Username="jsmith" FirstName="John" LastName="Smith" Email="" StudentID="" LastLogin="">
      <EnrolledSection CourseID="9" CourseName="Test Class" SectionID="14" SectionName="A">
      <Preferences/>
      <Exercises>
      <Exercise Exercise_id="1" Status="1" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
      <Exercise Exercise_id="2" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
      <Exercise Exercise_id="3" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
      <Exercise Exercise_id="4" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>

      </Exercises>

      </EnrolledSection>

      </StudentProfile>

        • 1. Re: E4X descendant-access (..) not working in simple case. Why?
          TeotiGraphix Level 3

          Hi,

           

          Using your sample XML,

           

          var exercises:XMLList = xml..Exercise;
          for each (var node:XML in exercises) {
              trace(node.@Exercise_id);
          }

           

          Produces the output;

           

          1
          2
          3
          4

           

          So that means node is an Excerise node. SOmetimes Flash Builder does not actually show the "node" toString() in the consol correctly.

           

          traceing exercises yeilds the correct XMLList

           

          <Exercise Exercise_id="1" Status="1" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
          <Exercise Exercise_id="2" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
          <Exercise Exercise_id="3" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/>
          <Exercise Exercise_id="4" Status="0" Enabled="true" IPValid="true" TimeValid="true" PasswordRequired="false"/

           

          Mike

          • 2. Re: E4X descendant-access (..) not working in simple case. Why?
            ssettlemyre Level 1

            Ok, so the problem was hidden by firefox. When I viewed the server response in the browser, FF was hiding a namespace attribute on the root tag. I removed this xmlns="" directive from the server response and now things work great.

             

            Thanks for your help.