【发布时间】:2011-11-28 05:12:07
【问题描述】:
如何获取 XML 节点上存在的所有属性?例如,我有以下 XML:
<item id="100">
<defaults width="10" height="100" post="true">
</item>
我想获取默认节点上的名称和值。
这是一些启动代码:
if (item.defaults) {
var attributes:Object = item.defaults.@*; // found in another post
for each (var value:String in attributes) {
trace("value "+value); // prints 10,100,true
}
for (var property:String in attributes) {
trace("property "+property); // prints 0,1,2 - I need to know the names
}
}
我找到了答案:
if (item.defaults) {
attributes = item.defaults.attributes();
attributesLength = attributes.length();
defaults = {};
for each (var attribute:Object in attributes) {
propertyName = String(attribute.name());
defaults[propertyName] = String(attribute);
}
}
【问题讨论】:
标签: xml actionscript-3 apache-flex