参考的例子
var x1:XML = <x1>
<a id = "52">AYY</a>
<a>AYY 2 </a>
<b>BEE</b>
<c>CEE</c>
</x1>;
trace(x1.toXMLString());
trace("___________");
delete x1.a.@id;
trace(x1.toXMLString());
trace("___________");
delete x1.b;
trace(x1.toXMLString());
trace("___________");
delete x1.a;
trace(x1.toXMLString());
输出
<x1>
<a id="52">AYY</a>
<a>AYY 2</a>
<b>BEE</b>
<c>CEE</c>
</x1>
___________
<x1>
<a>AYY</a>
<a>AYY 2</a>
<b>BEE</b>
<c>CEE</c>
</x1>
___________
<x1>
<a>AYY</a>
<a>AYY 2</a>
<c>CEE</c>
</x1>
___________
<x1>
<c>CEE</c>
</x1>
如果我只想删除一个元素怎么办?或者我想删除没有子元素的元素?
我只能使用删除 x1.a。荒谬的!我花了几个小时找不到简单的方法。
var list:XMLList = x1.elements('a');
for each(var x:XML in list){
if(....){
//make something done
//i want to delete this x from the xml object.while keep other node untouched.
}
}
让我知道你处理这个问题的方式。