1 Reply Latest reply on Aug 7, 2009 10:11 AM by Gregory Lafrance

    E4X maximum value

    Hessian0

      Hi

       

      I dont know how i can get the maximum or minimum value from an XML like this:

       

      <node>

          <subnode>

                <name>Jack</name>

                <age>21</age>

          </subnode>

      </node>

      <node>

          <subnode>

                <name>Maria</name>

                <age>55</age>

          </subnode>

          <subnode>

                <name>John</name>

                <age>37</age>

          </subnode>

      </node>

       

      I need to get maximum age attribute value using E4X syntax (in this case 55).

       

      Is that possible? Have you some ideas to solve my problem?

       

      Thanks

        • 1. Re: E4X maximum value
          Gregory Lafrance Level 6

          If this post answered your question or helped, please mark it as such.

           

          I don't know if you can do it purely with e4x, but this works:

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:XML id="myData">
              <data>
                <node>
                  <subnode>
                    <name>Jack</name>
                    <age>21</age>
                  </subnode>
                </node>
                <node>
                  <subnode>
                    <name>Maria</name>
                    <age>55</age>
                  </subnode>
                  <subnode>
                    <name>John</name>
                    <age>37</age>
                  </subnode>
                </node>
              </data>
            </mx:XML>
            <mx:Script>
              <![CDATA[
                import mx.utils.ArrayUtil;
               
                private function getMax(xl:XMLList):uint{
                  var maxVal:uint = 0;
                  for each(var val:uint in xl){
                    maxVal = Math.max(maxVal, val);
                  }
                  return maxVal;
                }
              ]]>
            </mx:Script>
            <mx:Text text="{getMax(myData..age)}"/>
          </mx:Application>

          1 person found this helpful