E4X is a very powerful and easy way to manipulate xml data in Flex.
Of course something so p[powerful can sometimes be confusing when it produces unexpected results.

     <mx:XML format="e4x" id="myXML">
           <order>
              <item id=‘1′>
                  <menuName>burger</menuName>
                  <price>3.95</price>
              </item>
              <item id=‘2′>
                  <menuName>fries</menuName>
                  <price>1.45</price>
             </item>
          </order>
      </mx:XML>
 

If you wanted to retrieve the price of the burger menuitem above, it is easily done with the e4x expression:

     <mx:XML format="e4x" id="myXML">
          <order>
              <item id=’1′>
                  <menuName>burger</menuName>
                  <menuName>burger</menuName>
                  <price>3.95</price>
              </item>
              <item id=’2′>
                  <menuName>fries</menuName>
                  <price>1.45</price>
             </item>
          </order>
      </mx:XML>
 

Then if you used the same expression, you actually would not get a value returned.
It is not obvious as to why this happens, but of course there is more than one way to skin a cat…
Here is an expression that will work:

    myXML.item.menuName.(text()=="burger").parent().price;
 

Here is a link to a Flex Builder 2.0.1 project (compiled with SDK hotfix1) containing a sample demonstrating the solution described above.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • digg
  • Technorati
  • Reddit
  • del.icio.us
  • Slashdot