tags:

views:

27

answers:

1

What are different approaches to filter and assign XML data to controls. my application get show when I do this using Array and looping??

A: 

Hope this helps. In the future try to be a bit more specific with your questions.

Use a for loop to iterate through nodes of the XML, as follows:

var total:Number = 0;
for each (var property:XML in myXML.item)
{
    var q:int = Number(property.@quantity);
    var p:Number = Number(property.price);
    var itemTotal:Number = q * p;
    total += itemTotal;
    trace(q + " " + property.menuName + " $" + itemTotal.toFixed(2))
}
trace("Total: $", total.toFixed(2));

You can use the parentheses operators-- ( and ) --to filter elements with a specific element name or attribute value. Consider the following XML object:

var x:XML = 
    <employeeList>
        <employee id="347">
            <lastName>Zmed</lastName>
            <firstName>Sue</firstName>
            <position>Data analyst</position>
        </employee>
        <employee id="348">
            <lastName>McGee</lastName>
            <firstName>Chuck</firstName>
            <position>Jr. data analyst</position>
        </employee>
    </employeeList>

The following expressions are all valid:

x.employee.(lastName ==
   "McGee")--This is the second employee
   node. 

x.employee.(lastName ==
   "McGee").firstName--This is the   
   firstName property of the second   
   employee node. 

x.employee.(lastName
   == "McGee").@id--This is the value of    the id attribute of the second   
   employee node. 

x.employee.(@id ==
   347)--The first employee node.

x.employee.(@id ==
   347).lastName--This is the lastName  
   property of the first employee node.

x.employee.(@id > 300)--This is an
   XMLList with both employee   
   properties.

x.employee.(position.toString().search("analyst")
      > -1)--This is an XMLList with both position properties.

See http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_04.html for more information.

Todd Moses