3 Replies Latest reply on Feb 26, 2010 1:38 AM by jake_flex

    E4X: How to get all elements of a subelement?

    jake_flex Level 2

      I'm trying to get all elements of a subelement with E4X. I think I've tried every possible function, child(), children(), elements(), descendants(), with no success. I just can't figure it out.

       

      My XML is similar to the one below

       

      <mx:XML id="myXML" >
        <top>
          <sub1 id="uno">
            <sub2>hello</sub2>
            <sub3>world</sub3>
          </sub1>
          <sub1 id="duo">
            <sub2>ok</sub2>
            <sub3>ko</sub3>
          </sub1>
          <sub1 id="tre">
            <sub2>3</sub2>
            <sub3>three</sub3>
          </sub1>
        </top>
      </mx:XML>
      

       

      I need to get a list containing all the elements in the first sub element (sub1). In other words, I need a list that contains


      <sub2>hello</sub2>
      <sub3>world</sub3>
      

       

      All the functions I have tried either return all the sub elements on the same level, like

       

      <sub2>hello</sub2>
      <sub3>world</sub3>
      <sub2>ok</sub2>
      <sub3>ko</sub3>
      <sub2>3</sub2>
      <sub3>three</sub3>
      

       

      or that they return only the first sub sub element as

       

      <sub2>hello</sub2>
      

       

      or

       

      <sub2>hello</sub2>
      <sub2>ok</sub2>
      <sub2>3</sub2>
      

       

      Can anyone point me to the correct function on how achieve what I want?

       

      Thanks.

       

      P.S. I highlighted the question in green, so that it'll be easier to spot from the thread, since there's quite a lot of examples.