0 Replies Latest reply on Sep 25, 2009 7:20 PM by SunWuKonga

    Referencing XML object fields with descendent accessor (..)

    SunWuKonga

      This works:

       

       

           var example:XML =     <result type="success">
                                    <products>
                                         <product>...</product>
                                         <product>...</product>
                                         ...                 
                                    </products></result>;
      

       

       

           for each(var item:XML in example..product)
           {
                ...
           }
      

       

      as does the following: (My hackneyed solution)

       

       

           for each(var item:XML in XML(JavaServiceHandler(e.currentTarget).response.toString())..product)
           {
                ... 
           }
      

       

      Note that the explicit cast using JavaServiceHandler() is not necessary. The target Object e.currentTarget of type JavaServiceHandler has a public field variable

       

           public var response:XML;
      

       

      This call:

       

           JavaServiceHandler(e.currentTarget).response.toString();
      

       

      returns a string that exactly matches the var example:XML above, in fact 'example' is a copy and paste.

       

      However, this does NOT work:

       

           for each(var item:XML in JavaServiceHandler(e.currentTarget).response..product)
      

       

      nor this:

           for each(var item:XML in XML(JavaServiceHandler(e.currentTarget).response)..product)
      

      nor this:

       

       

       

           for each(var item:* in JavaServiceHandler(e.currentTarget).response..product)
      

      nor this:

       

           for each(var item:* in (e.currentTarget).response..product)
      

       

       

       

      Does anyone know why?