开发者

how to find a descendant with highest value in xml actionscript

开发者 https://www.devze.com 2023-01-29 18:31 出处:网络
ok so in actionscript using xml I can find all the nodes of the same name using xmlList.descendants(\"nodename\");

ok so in actionscript using xml I can find all the nodes of the same name using

xmlList.descendants("nodename");

and that returns me a XMLlist of those nodes that exist within the xmlList I provided all well and good but now I want to only get the one node of the returned value that has the largest value.

So the question is this. Do I have 开发者_开发技巧to loop through the resulting nodes or can I get that node without a loop maybe some other xmllist function I'm not aware of ?

thanks


You could do something like this instead of a loop:

var xml:XML = 
<xml>
    <element id="1" value="22" />
    <element id="2" value="33" />
    <element id="3" value="11" />
</xml>;

var max:Number = Number.MIN_VALUE;
xml.element.(max = Math.max(max, @value));
var top:XMLList = xml.element.(@value == max);

To be honest, I sometimes have a hard time getting my head around how these kinds of E4X expressions work, but they do.


With this xml:

var data:XML = <items>  
         <item name="Wii">   
             <price>364.00</price>  
         </item>  
         <item name="Wii">   
             <price>249.99</price>  
         </item>  
         <item name="X-Box 360">    
             <price>399.99</price>  
         </item>  
         <item name="PlayStation 3">  
             <price>599.99</price>  
        </item>  
</items>;

var filter:XMLList = data.item.(price > 300);
            trace(filter);

You will get an output of:

<item name="Wii">
  <source>Amazon</source>
  <price>364.00</price>
</item>
<item name="X-Box 360">
  <source>Amazon</source>
  <price>399.99</price>
</item>
<item name="PlayStation 3">
  <source>Amazon</source>
  <price>599.99</price>
</item>

I think this is the closest you could get with getting numbers,and there is no a way you can get a max/min value straight from XML (you probably need to create some functions) you can read an implementation of it here : MinMaxXML

0

精彩评论

暂无评论...
验证码 换一张
取 消