如何获取XML节点上存在的所有属性?例如,我有以下XML:如何获取XML节点上的所有属性
<item id="100">
<defaults width="10" height="100" post="true">
</item>
我想获取默认节点上的名称和值。
下面是一些入门代码:
if (item.defaults) {
var attributes:Object = [email protected]*; // 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);
}
}
谢谢大家解答吧! –
每个人都得到星星 –