Reputation: 17770
How do I delete an attribute on an XML node in E4X? I thought this would be easier but I haven't found any examples.
I tried:
delete xml.attribute("myAttribute");
which gives me the following error:
TypeError: Error #1119: Delete operator is not supported with operand of type XMLList.
and I've tried:
xml.attribute("myAttribute") = null;
which causes a compiler error.
Upvotes: 2
Views: 651
Reputation: 5267
In you example just add the [0]
in the resulted XMLList, to ensure you delete a single attribute node, it should work:
delete xml.@attributename[0];
Actually, for me delete
with XMLList
works as well for simple cases (without complex e4x search constructions):
var x:XML = <x><c a="1"/><c a="2"/></x>;
trace("0", x.toXMLString());
delete x.c.@a;
trace("1", x.toXMLString());
output:
[trace] 0 <x>
[trace] <c a="1"/>
[trace] <c a="2"/>
[trace] </x>
[trace] 1 <x>
[trace] <c/>
[trace] <c/>
[trace] </x>
Upvotes: 3