2010-02-09 139 views

回答

0

希望这会有所帮助。今后试着对你的问题做更具体的描述。

使用for循环通过XML的节点进行迭代,如下所示:

var total:Number = 0; 
for each (var property:XML in myXML.item) 
{ 
    var q:int = Number([email protected]); 
    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)); 

可以使用括号operators--(和)--to过滤元件具有特定元素名称或属性值。考虑下面的XML对象:

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> 

以下表达式都是有效的:

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")[email protected] 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. 

有关更多信息,请参见http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_04.html