1 Reply Latest reply on Apr 2, 2009 1:58 AM by Lehaleha

    how to find the maximum value in xml list

    sk2910
      hi , i have an xml list..in that how to find the maximum value of one child node..

      Is there any predefined function to find the maximum value for a particular child node?

      I'm using this function:
      private function findValue(xmlData:XMLList, nodeName:String, options:Object=null):String
      {
      var coll:XMLListCollection = new XMLListCollection(xmlData.row[nodeName]);
      var tmp:Array = new Array();

      for(var i:int = 0; i < coll.children().length(); i++)
      {
      tmp.push(coll );
      }

      var sorted:Array = tmp.sort(options);
      return sorted[0];
      }

      its working fine..but in the xmllist 2000 nodes are there..performance wise its going down..

      ..thnx in advance
        • 1. Re: how to find the maximum value in xml list
          Lehaleha
          hi,
          just wanna point, that copy elements to array and sort it - its a bad decision anyway. It will be much better just to iterate through children of the "coll" var one time.

          Ohhr... E... And actually your code is... very strange ;) Are you sure that there is no mistake in this loop:

          for(var i:int = 0; i < coll.children().length(); i++)
          {
          tmp.push( coll); //??
          }