【XML】遍历xml子节点
var myXML:XML = <order> <item id='1' quantity="5"> <menuName>burger</menuName> <price>3.95</price> </item> <item id='2' quantity="3"> <menuName>fries</menuName> <price>1.45</price> </item> </order>; var newItem:XML = <item id="3" quantity="2"> <menuName>medium cola</menuName> <price>1.25</price> </item>; myXML.appendChild(newItem); 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)); /* 5 burger $19.75 3 fries $4.35 2 medium cola $2.50 Total: $ 26.60 */