Tuesday, March 30, 2010

E4X maximum value

Hi

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

%26lt;node%26gt;

?%26lt;subnode%26gt;

?%26lt;name%26gt;Jack%26lt;/name%26gt;

?%26lt;age%26gt;21%26lt;/age%26gt;

?%26lt;/subnode%26gt;

%26lt;/node%26gt;

%26lt;node%26gt;

?%26lt;subnode%26gt;

?%26lt;name%26gt;Maria%26lt;/name%26gt;

?%26lt;age%26gt;55%26lt;/age%26gt;

?%26lt;/subnode%26gt;

?%26lt;subnode%26gt;

?%26lt;name%26gt;John%26lt;/name%26gt;

?%26lt;age%26gt;37%26lt;/age%26gt;

?%26lt;/subnode%26gt;

%26lt;/node%26gt;

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

E4X maximum value

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:

%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application xmlns:mx=''http://www.adobe.com/2006/mxml''%26gt;
?%26lt;mx:XML id=''myData''%26gt;
?%26lt;data%26gt;
?%26lt;node%26gt;
?%26lt;subnode%26gt;
?%26lt;name%26gt;Jack%26lt;/name%26gt;
?%26lt;age%26gt;21%26lt;/age%26gt;
?%26lt;/subnode%26gt;
?%26lt;/node%26gt;
?%26lt;node%26gt;
?%26lt;subnode%26gt;
?%26lt;name%26gt;Maria%26lt;/name%26gt;
?%26lt;age%26gt;55%26lt;/age%26gt;
?%26lt;/subnode%26gt;
?%26lt;subnode%26gt;
?%26lt;name%26gt;John%26lt;/name%26gt;
?%26lt;age%26gt;37%26lt;/age%26gt;
?%26lt;/subnode%26gt;
?%26lt;/node%26gt;
?%26lt;/data%26gt;
?%26lt;/mx:XML%26gt;
?%26lt;mx:Script%26gt;
?%26lt;![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;
?}
?]]%26gt;
?%26lt;/mx:Script%26gt;
?%26lt;mx:Text text=''{getMax(myData..age)}''/%26gt;
%26lt;/mx:Application%26gt;

No comments:

Post a Comment