1 Reply Latest reply on May 17, 2006 12:42 AM by AnantG

    E4X demo - single file

    nickull
      Wrote a little demo app to test/demo the E4X handling of XML in a Flex application. The file can be cut and pasted into Flex Builder 2.0 beta 2 and you only need to uncomment the lines for the feature you want to try, then build and run.

      If you cannot see it here, you may download it from http://technoracle.blogspot.com/

      Enjoy - duane nickull
      ****************************************************************************************** **************************
      <?xml version="1.0" encoding="utf-8"?>
      <!--(c) 2006 Duane Nickull (dnickull@adobe.com) - all rights reserved
      You are free to use this sample demonstrating how to manipulate XML
      data using the E4X component of ActionScript 3.0. This file is designed
      to be used in the Flex builder 2.0 Beta 2.0 or later. No warranties
      exist to the accuracy of this code and you agree to use it completely
      at your own risk and assume all responsibilities for such use.

      For more samples, check http://technoracle.blogspot.com or the Adobe
      Labs website.
      -->



      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      backgroundAlpha="0">
      <mx:Script>
      <![CDATA[

      var myGMLData =
      <MultiLineString srsName=" http://www.opengis.net/gml/srs/epsg.xml">
      <lineStringMember value="1">
      <LineString>
      <coord>
      <X>56.1</X>
      <Y>0.45</Y>
      </coord>
      <coord>
      <X>67.23</X>
      <Y>0.98</Y>
      </coord>
      </LineString>
      </lineStringMember>

      <lineStringMember value="2">
      <LineString>
      <coord><X>46.71</X><Y>9.25</Y></coord>
      <coord><X>56.88</X><Y>10.44</Y></coord>
      </LineString>
      </lineStringMember>

      <lineStringMember value="3">
      <LineString>
      <coord><X>324.1</X><Y>219.7</Y></coord>
      <coord><X>0.45</X><Y>4.56</Y></coord>
      </LineString>
      </lineStringMember>
      </MultiLineString>
      ]]>

      </mx:Script>

      <!--uncomment any statement to display the results-->
      <mx:Label id="XCoordinate" text="{myGMLData.lineStringMember[0].LineString.coord[0].X}"/>

      <mx:Label id="YCoordinate" text="{myGMLData.lineStringMember[0].LineString.coord.Y[0]}"/>

      <!--DOT::FRAGMENT: returns an XML Fragment-->
      <!--mx:Label id="FragmentReturned" text="{myGMLData.lineStringMember[1]}" height="179" width="233"/-->

      <!--PARENTHESIS: Filters the XML fragment based on X having an exact value of 324.1-->
      <!--mx:Label id="Parenthesis" text="{myGMLData.lineStringMember.LineString.coord.(X == 324.1)}" height="179" width="233"/-->

      <!--DESCENDENT: returns all instances of Y that are descendents of lineStringMember-->
      <!--mx:Label id="Descendent" text="{myGMLData.lineStringMember..Y}" height="220" width="235"/-->

      <!--ATTRIBUTE: returns the attribute-->
      <!--mx:Label id="Attribute" text="{myGMLData.lineStringMember.(@value = 2)}"/-->

      <!--COMBINATION example. Note use of math operators which cast values to integers-->
      <mx:Label id="combination" text="{myGMLData.lineStringMember..coord.(Y > 10.44)}" height="136" width="326"/>

      </mx:Application>
        • 1. Re: E4X demo - single file
          AnantG
          That's nice. You could replace <mx:Label /> with <mx:Text /> everywhere in the example and then the outputs would appear in multiLine rather than in a single line with toolTips popping up, since the textField in label has multiLine set to false by default.