如何獲取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);
}
}
謝謝大家解答吧! –
每個人都得到星星 –