var type:Array = ["type0", "type1", "type2"]; var property:Array = [["20","0","1.jpg"], ["60","0","2.jpg"], ["120","0","3.jpg"]];
var data:XML = new XML("<data type='any'></data>"); for (var i:int = 0; i < property.length; i++) { var node:XML = new XML(); node = <item type={type[i]}> <property x={property[i][0]} y={property[i][1]}></property> <path url={property[i][2]}></path> </item>; data = data.appendChild(node) } trace(data);
打印内容:
<data type="any"> <item type="type0"> <property x="20" y="0"/> <path url="1.jpg"/> </item> <item type="type1"> <property x="60" y="0"/> <path url="2.jpg"/> </item> <item type="type2"> <property x="120" y="0"/> <path url="3.jpg"/> </item> </data>