【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 */
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步