-
1. Re: add attribute to a XML node at a specific position
liangyongning May 2, 2012 7:52 PM (in response to eprevot123)there's no native method for this, maybe you should create some functions for this. just like
private function setAttribute(node:XML, name:String, value:String, index:int = -1):void
{
var attrs:XMLList = node.attributes().copy(),
l:int = attrs.length();
if(index == -1 || index > l - 1)
{
node.@[name] = value;
}
else
{
delete node.@*;
var idx:int = 0;
for (var i:int = 0; i < l + 1; i++)
{
if(i == index)
{
node.@[name] = value;
}
else
{
var attr:XML = attrs[idx];
node.@[attr.name()] = attr.toString();
idx++;
}
}
}
}
and use it like this:
setAttribute(myNode, "otherAttribute", "abc", 0);

